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..5e3e33f2d69ef2b5c58be978324f98f60da11315 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) const { |
+ return base::ContainsKey(overscan_started_, id); |
+ } |
+ |
+ bool calibration_changed(const std::string& id) const { |
+ 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); |
}; |
@@ -177,20 +220,35 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { |
#else // !defined(OS_CHROMEOS) |
+constexpr char kTestManifest[] = |
+ "{\n" |
+ " \"name\": \"Test\",\n" |
+ " \"version\": \"1.0\",\n" |
+ " \"app\": {\n" |
+ " \"background\": {\n" |
+ " \"scripts\": [\"background.js\"]\n" |
+ " }\n" |
+ " }\n" |
+ "}"; |
+ |
+constexpr char kTestManifestKiosk[] = |
+ "{\n" |
+ " \"name\": \"Test\",\n" |
+ " \"version\": \"1.0\",\n" |
+ " \"app\": {\n" |
+ " \"background\": {\n" |
+ " \"scripts\": [\"background.js\"]\n" |
+ " }\n" |
+ " },\n" |
+ " \"kiosk_enabled\": true\n" |
+ "}"; |
+ |
// TODO(stevenjb): Add API tests for {GS}etDisplayLayout. That code currently |
// lives in src/chrome but should be getting moved soon. |
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(kTestManifest)); |
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(kTestManifestKiosk)); |
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(kTestManifestKiosk)); |
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(kTestManifestKiosk)); |
+ 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 |