Commit d3d59a97 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Add chromeosInfoPrivate stylusStatus API (part 2)

Adds a third option for stylusStatus:
- "seen" if supported and stylus has been used at least once or the
  device comes with an internal stylus.

Follow-up to https://crrev.com/c/1123320.

      eve: "supported", then "seen"; caroline: "seen")

Bug: 632814
Test: browser_tests, manually (banjo: "unsupported";
Change-Id: I155dd3e98e5d68990aef304be5ac6c1d8d4f5edc
Reviewed-on: https://chromium-review.googlesource.com/1123397
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579559}
parent cd2b196c
...@@ -175,7 +175,8 @@ PaletteTray::~PaletteTray() { ...@@ -175,7 +175,8 @@ PaletteTray::~PaletteTray() {
// static // static
void PaletteTray::RegisterLocalStatePrefs(PrefRegistrySimple* registry) { void PaletteTray::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kHasSeenStylus, false); registry->RegisterBooleanPref(prefs::kHasSeenStylus, false,
PrefRegistry::PUBLIC);
} }
// static // static
......
...@@ -178,9 +178,13 @@ const char kPropertyStylusStatus[] = "stylusStatus"; ...@@ -178,9 +178,13 @@ const char kPropertyStylusStatus[] = "stylusStatus";
const char kStylusStatusUnsupported[] = "unsupported"; const char kStylusStatusUnsupported[] = "unsupported";
// Value to which stylusStatus property is set when the device supports stylus // Value to which stylusStatus property is set when the device supports stylus
// input. // input, but no stylus has been seen before.
const char kStylusStatusSupported[] = "supported"; const char kStylusStatusSupported[] = "supported";
// Value to which stylusStatus property is set when the device has a built-in
// stylus or a stylus has been seen before.
const char kStylusStatusSeen[] = "seen";
const struct { const struct {
const char* api_name; const char* api_name;
const char* preference_name; const char* preference_name;
...@@ -352,8 +356,10 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue( ...@@ -352,8 +356,10 @@ std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue(
return std::make_unique<base::Value>(kStylusStatusUnsupported); return std::make_unique<base::Value>(kStylusStatusUnsupported);
} }
// TODO(michaelpg): Return "seen" if stylus has been used. bool seen = g_browser_process->local_state()->HasPrefPath(
return std::make_unique<base::Value>(kStylusStatusSupported); ash::prefs::kHasSeenStylus);
return std::make_unique<base::Value>(seen ? kStylusStatusSeen
: kStylusStatusSupported);
} }
if (property_name == kPropertyClientId) { if (property_name == kPropertyClientId) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/stylus_utils.h" #include "ash/public/cpp/stylus_utils.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/values.h" #include "base/values.h"
...@@ -11,11 +12,16 @@ ...@@ -11,11 +12,16 @@
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/stub_install_attributes.h" #include "chrome/browser/chromeos/settings/stub_install_attributes.h"
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/settings/cros_settings_names.h" #include "chromeos/settings/cros_settings_names.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "services/ui/public/cpp/input_devices/input_device_client_test_api.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/events/test/event_generator.h"
namespace { namespace {
...@@ -138,12 +144,61 @@ IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateTest, StylusUnsupported) { ...@@ -138,12 +144,61 @@ IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateTest, StylusUnsupported) {
} }
IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateTest, StylusSupported) { IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateTest, StylusSupported) {
ash::stylus_utils::SetHasStylusInputForTesting(); ui::InputDeviceClientTestApi test_api;
ui::TouchscreenDevice touchscreen(1,
ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0);
touchscreen.has_stylus = true;
test_api.SetTouchscreenDevices({touchscreen});
ASSERT_TRUE(RunPlatformAppTestWithArg("chromeos_info_private/extended", ASSERT_TRUE(RunPlatformAppTestWithArg("chromeos_info_private/extended",
"stylus supported")) "stylus supported"))
<< message_; << message_;
} }
// TODO(https://crbug.com/814675): Excluded from Mash because pointer events
// aren't seen.
IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateTest, StylusSeen) {
ui::InputDeviceClientTestApi test_api;
ui::TouchscreenDevice touchscreen(1,
ui::InputDeviceType::INPUT_DEVICE_INTERNAL,
"Touchscreen", gfx::Size(1024, 768), 0);
touchscreen.has_stylus = true;
test_api.SetTouchscreenDevices({touchscreen});
ui::test::EventGenerator generator(browser()->window()->GetNativeWindow());
generator.EnterPenPointerMode();
generator.PressTouch();
generator.ReleaseTouch();
generator.ExitPenPointerMode();
ASSERT_TRUE(RunPlatformAppTestWithArg("chromeos_info_private/extended",
"stylus seen"))
<< message_;
}
class ChromeOSInfoPrivateInternalStylusTest : public ChromeOSInfoPrivateTest {
public:
ChromeOSInfoPrivateInternalStylusTest() = default;
~ChromeOSInfoPrivateInternalStylusTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
ChromeOSInfoPrivateTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(ash::switches::kHasInternalStylus);
}
private:
DISALLOW_COPY_AND_ASSIGN(ChromeOSInfoPrivateInternalStylusTest);
};
IN_PROC_BROWSER_TEST_F(ChromeOSInfoPrivateInternalStylusTest,
StylusSeenInternal) {
ash::stylus_utils::SetHasStylusInputForTesting();
ASSERT_TRUE(RunPlatformAppTestWithArg("chromeos_info_private/extended",
"stylus seen"))
<< message_;
}
class ChromeOSArcInfoPrivateTest : public ChromeOSInfoPrivateTest { class ChromeOSArcInfoPrivateTest : public ChromeOSInfoPrivateTest {
public: public:
ChromeOSArcInfoPrivateTest() = default; ChromeOSArcInfoPrivateTest() = default;
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
{ {
"id": "StylusStatus", "id": "StylusStatus",
"type": "string", "type": "string",
"enum": ["unsupported", "supported"], "enum": ["unsupported", "supported", "seen"],
"description": "Status of stylus." "description": "Status of stylus."
} }
], ],
......
...@@ -1792,6 +1792,7 @@ test("browser_tests") { ...@@ -1792,6 +1792,7 @@ test("browser_tests") {
"//services/preferences/public/cpp", "//services/preferences/public/cpp",
"//services/preferences/public/mojom", "//services/preferences/public/mojom",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//services/ui/public/cpp/input_devices:test_support",
"//ui/keyboard:test_support", "//ui/keyboard:test_support",
"//ui/login:resources", "//ui/login:resources",
"//url", "//url",
......
...@@ -53,6 +53,9 @@ chrome.app.runtime.onLaunched.addListener(function() { ...@@ -53,6 +53,9 @@ chrome.app.runtime.onLaunched.addListener(function() {
case 'stylus supported': case 'stylus supported':
chrome.test.assertEq('supported', values['stylusStatus']); chrome.test.assertEq('supported', values['stylusStatus']);
break; break;
case 'stylus seen':
chrome.test.assertEq('seen', values['stylusStatus']);
break;
} }
})); }));
}); });
......
...@@ -304,4 +304,8 @@ ...@@ -304,4 +304,8 @@
-ShelfAppBrowserTestNoDefaultBrowser.AltNumberBrowserTabbing -ShelfAppBrowserTestNoDefaultBrowser.AltNumberBrowserTabbing
-ShelfAppBrowserTestNoDefaultBrowser.BrowserShortcutLauncherItemController -ShelfAppBrowserTestNoDefaultBrowser.BrowserShortcutLauncherItemController
# Excluded from Mash because pointer events from EventGenerator aren't seen.
# https://crbug.com/814675
-ChromeOSInfoPrivateTest.StylusSeen
# See comment at top of file regarding adding test exclusions. # See comment at top of file regarding adding test exclusions.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment