Chromium Code Reviews| Index: extensions/browser/api/system_display/system_display_apitest.cc |
| diff --git a/extensions/browser/api/system_display/system_display_apitest.cc b/extensions/browser/api/system_display/system_display_apitest.cc |
| index 36943530e17b344622544ed17827c4193e2ae1c3..592bbe790b13cfb9b23fe08c5e905b79277d2e16 100644 |
| --- a/extensions/browser/api/system_display/system_display_apitest.cc |
| +++ b/extensions/browser/api/system_display/system_display_apitest.cc |
| @@ -4,10 +4,12 @@ |
| #include <stdint.h> |
| +#include <set> |
| #include <utility> |
| #include "base/debug/leak_annotations.h" |
| #include "base/macros.h" |
| +#include "base/stl_util.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "build/build_config.h" |
| #include "extensions/browser/api/system_display/display_info_provider.h" |
| @@ -15,6 +17,7 @@ |
| #include "extensions/browser/api_test_utils.h" |
| #include "extensions/common/api/system_display.h" |
| #include "extensions/shell/test/shell_apitest.h" |
| +#include "extensions/test/result_catcher.h" |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| @@ -92,6 +95,36 @@ class MockDisplayInfoProvider : public DisplayInfoProvider { |
| unified_desktop_enabled_ = enable; |
| } |
| + bool OverscanCalibrationStart(const std::string& id) override { |
| + if (base::ContainsKey(overscan_started_, id)) |
| + return false; |
| + overscan_started_.insert(id); |
| + return true; |
| + } |
| + |
| + bool OverscanCalibrationAdjust( |
| + const std::string& id, |
| + const api::system_display::Insets& delta) override { |
| + if (!base::ContainsKey(overscan_started_, id)) |
| + return false; |
| + overscan_adjusted_.insert(id); |
| + return true; |
| + } |
| + |
| + bool OverscanCalibrationReset(const std::string& id) override { |
| + if (!base::ContainsKey(overscan_started_, id)) |
| + return false; |
| + overscan_adjusted_.erase(id); |
| + return true; |
| + } |
| + |
| + bool OverscanCalibrationComplete(const std::string& id) override { |
| + if (!base::ContainsKey(overscan_started_, id)) |
| + return false; |
| + overscan_started_.erase(id); |
| + return true; |
| + } |
| + |
| std::unique_ptr<base::DictionaryValue> GetSetInfoValue() { |
| return std::move(set_info_value_); |
| } |
| @@ -100,6 +133,14 @@ class MockDisplayInfoProvider : public DisplayInfoProvider { |
| bool unified_desktop_enabled() const { return unified_desktop_enabled_; } |
| + bool calibration_started(const std::string& id) { |
|
xiyuan
2016/12/07 21:32:40
nit: const method?
stevenjb
2016/12/07 21:54:42
Done.
|
| + return base::ContainsKey(overscan_started_, id); |
| + } |
| + |
| + bool calibration_changed(const std::string& id) { |
|
xiyuan
2016/12/07 21:32:40
nit: const method?
stevenjb
2016/12/07 21:54:42
Done.
|
| + return base::ContainsKey(overscan_adjusted_, id); |
| + } |
| + |
| private: |
| // Update the content of the |unit| obtained for |display| using |
| // platform specific method. |
| @@ -127,6 +168,8 @@ class MockDisplayInfoProvider : public DisplayInfoProvider { |
| std::unique_ptr<base::DictionaryValue> set_info_value_; |
| std::string set_info_display_id_; |
| bool unified_desktop_enabled_ = false; |
| + std::set<std::string> overscan_started_; |
| + std::set<std::string> overscan_adjusted_; |
| DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); |
| }; |
| @@ -157,6 +200,29 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplayInfo) { |
| ASSERT_TRUE(RunAppTest("system/display/info")) << message_; |
| } |
| +const char test_manifest[] = |
|
xiyuan
2016/12/07 21:32:40
nit: const -> constexpr, test_manifest -> kTestMan
stevenjb
2016/12/07 21:54:42
Done.
|
| + "{\n" |
| + " \"name\": \"Test\",\n" |
| + " \"version\": \"1.0\",\n" |
| + " \"app\": {\n" |
| + " \"background\": {\n" |
| + " \"scripts\": [\"background.js\"]\n" |
| + " }\n" |
| + " }\n" |
| + "}"; |
| + |
| +const char test_manifest_kiosk[] = |
|
xiyuan
2016/12/07 21:32:40
nit: const -> constexpr, test_manifest_kiosk -> kT
stevenjb
2016/12/07 21:54:42
Done.
|
| + "{\n" |
| + " \"name\": \"Test\",\n" |
| + " \"version\": \"1.0\",\n" |
| + " \"app\": {\n" |
| + " \"background\": {\n" |
| + " \"scripts\": [\"background.js\"]\n" |
| + " }\n" |
| + " },\n" |
| + " \"kiosk_enabled\": true\n" |
| + "}"; |
| + |
| #if !defined(OS_CHROMEOS) |
| IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { |
| @@ -182,15 +248,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { |
| IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { |
| std::unique_ptr<base::DictionaryValue> test_extension_value( |
| - api_test_utils::ParseDictionary("{\n" |
| - " \"name\": \"Test\",\n" |
| - " \"version\": \"1.0\",\n" |
| - " \"app\": {\n" |
| - " \"background\": {\n" |
| - " \"scripts\": [\"background.js\"]\n" |
| - " }\n" |
| - " }\n" |
| - "}")); |
| + api_test_utils::ParseDictionary(test_manifest)); |
| scoped_refptr<Extension> test_extension( |
| api_test_utils::CreateExtension(test_extension_value.get())); |
| @@ -212,16 +270,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { |
| IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) { |
| std::unique_ptr<base::DictionaryValue> test_extension_value( |
| - api_test_utils::ParseDictionary("{\n" |
| - " \"name\": \"Test\",\n" |
| - " \"version\": \"1.0\",\n" |
| - " \"app\": {\n" |
| - " \"background\": {\n" |
| - " \"scripts\": [\"background.js\"]\n" |
| - " }\n" |
| - " },\n" |
| - " \"kiosk_enabled\": true\n" |
| - "}")); |
| + api_test_utils::ParseDictionary(test_manifest_kiosk)); |
| scoped_refptr<Extension> test_extension( |
| api_test_utils::CreateExtension(test_extension_value.get())); |
| @@ -264,16 +313,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) { |
| IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) { |
| std::unique_ptr<base::DictionaryValue> test_extension_value( |
| - api_test_utils::ParseDictionary("{\n" |
| - " \"name\": \"Test\",\n" |
| - " \"version\": \"1.0\",\n" |
| - " \"app\": {\n" |
| - " \"background\": {\n" |
| - " \"scripts\": [\"background.js\"]\n" |
| - " }\n" |
| - " },\n" |
| - " \"kiosk_enabled\": true\n" |
| - "}")); |
| + api_test_utils::ParseDictionary(test_manifest_kiosk)); |
| scoped_refptr<Extension> test_extension( |
| api_test_utils::CreateExtension(test_extension_value.get())); |
| { |
| @@ -303,6 +343,70 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) { |
| } |
| } |
| +IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationStart) { |
| + const std::string id = "display0"; |
| + std::unique_ptr<base::DictionaryValue> test_extension_value( |
| + api_test_utils::ParseDictionary(test_manifest_kiosk)); |
| + scoped_refptr<Extension> test_extension( |
| + api_test_utils::CreateExtension(test_extension_value.get())); |
| + |
| + // Setup MockDisplayInfoProvider. |
| + api::system_display::DisplayProperties params; |
| + provider_->SetInfo(id, params, nullptr); |
| + |
| + // Call OverscanCalibrationStart. |
| + scoped_refptr<SystemDisplayOverscanCalibrationStartFunction> start_function( |
| + new SystemDisplayOverscanCalibrationStartFunction()); |
| + start_function->set_extension(test_extension.get()); |
| + start_function->set_has_callback(true); |
| + ASSERT_TRUE(api_test_utils::RunFunction( |
| + start_function.get(), "[\"" + id + "\"]", browser_context())); |
| + |
| + ASSERT_TRUE(provider_->calibration_started(id)); |
| + |
| + // Call OverscanCalibrationComplete. |
| + scoped_refptr<SystemDisplayOverscanCalibrationCompleteFunction> |
| + complete_function(new SystemDisplayOverscanCalibrationCompleteFunction()); |
| + complete_function->set_extension(test_extension.get()); |
| + complete_function->set_has_callback(true); |
| + ASSERT_TRUE(api_test_utils::RunFunction( |
| + complete_function.get(), "[\"" + id + "\"]", browser_context())); |
| + |
| + ASSERT_FALSE(provider_->calibration_started(id)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationApp) { |
| + // Setup MockDisplayInfoProvider. |
| + const std::string id = "display0"; |
| + api::system_display::DisplayProperties params; |
| + provider_->SetInfo(id, params, nullptr); |
| + |
| + ASSERT_TRUE(RunAppTest("system/display/overscan")) << message_; |
| + |
| + ASSERT_FALSE(provider_->calibration_started(id)); |
| + ASSERT_TRUE(provider_->calibration_changed(id)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationAppNoComplete) { |
| + // Setup MockDisplayInfoProvider. |
| + const std::string id = "display0"; |
| + api::system_display::DisplayProperties params; |
| + provider_->SetInfo(id, params, nullptr); |
| + |
| + ResultCatcher catcher; |
| + const Extension* extension = LoadApp("system/display/overscan_no_complete"); |
| + ASSERT_TRUE(extension); |
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| + |
| + // Calibration was started by the app but not completed. |
| + ASSERT_TRUE(provider_->calibration_started(id)); |
| + |
| + // Unloading the app should complete the calibraiton (and hide the overlay). |
| + UnloadApp(extension); |
| + ASSERT_FALSE(provider_->calibration_changed(id)); |
| + ASSERT_FALSE(provider_->calibration_started(id)); |
| +} |
| + |
| #endif // !defined(OS_CHROMEOS) |
| } // namespace extensions |