OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #include "base/command_line.h" | 4 |
5 #include "base/message_loop.h" | 5 #include "chrome/browser/extensions/api/system_info_display/system_info_display_ api.h" |
6 | |
6 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
7 #include "chrome/browser/extensions/api/system_info_display/display_info_provide r.h" | 8 #include "chrome/browser/extensions/api/system_info_display/display_info_provide r.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
10 #include "chrome/common/chrome_switches.h" | 11 |
12 namespace utils = extension_function_test_utils; | |
11 | 13 |
12 namespace extensions { | 14 namespace extensions { |
13 | 15 |
14 using api::system_info_display::Bounds; | 16 using api::system_info_display::Bounds; |
15 using api::system_info_display::DisplayUnitInfo; | 17 using api::system_info_display::DisplayUnitInfo; |
16 | 18 |
17 class MockDisplayInfoProvider : public DisplayInfoProvider { | 19 class MockDisplayInfoProvider : public DisplayInfoProvider { |
18 public: | 20 public: |
19 virtual bool QueryInfo(DisplayInfo* info) OVERRIDE { | 21 virtual bool QueryInfo(DisplayInfo* info) OVERRIDE { |
20 info->clear(); | 22 info->clear(); |
(...skipping 20 matching lines...) Expand all Loading... | |
41 unit->overscan.bottom = 80; | 43 unit->overscan.bottom = 80; |
42 } | 44 } |
43 unit->work_area.left = 0; | 45 unit->work_area.left = 0; |
44 unit->work_area.top = 0; | 46 unit->work_area.top = 0; |
45 unit->work_area.width = 960; | 47 unit->work_area.width = 960; |
46 unit->work_area.height = 720; | 48 unit->work_area.height = 720; |
47 info->push_back(unit); | 49 info->push_back(unit); |
48 } | 50 } |
49 return true; | 51 return true; |
50 } | 52 } |
53 | |
54 virtual void SetInfo( | |
55 const std::string& display_id, | |
56 const api::system_info_display::SetDisplayUnitInfoParams& params, | |
57 const SetInfoCallback& callback) OVERRIDE { | |
58 // Should get called only once per test case. | |
59 EXPECT_FALSE(set_info_value_); | |
60 set_info_value_ = params.ToValue(); | |
61 set_info_display_id_ = display_id; | |
62 callback.Run(true, std::string()); | |
63 } | |
64 | |
65 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { | |
66 return set_info_value_.Pass(); | |
67 } | |
68 | |
69 std::string GetSetInfoDisplayId() { | |
oshima
2013/06/13 19:12:40
const
tbarzic
2013/06/13 20:58:15
Done.
| |
70 return set_info_display_id_; | |
71 } | |
72 | |
51 private: | 73 private: |
52 virtual ~MockDisplayInfoProvider() {} | 74 virtual ~MockDisplayInfoProvider() {} |
53 | 75 |
76 scoped_ptr<base::DictionaryValue> set_info_value_; | |
77 std::string set_info_display_id_; | |
oshima
2013/06/13 19:12:40
DISALLOW_COPY_AND_ASSIGN
tbarzic
2013/06/13 20:58:15
there is an assign in SetupOnMainThread
oshima
2013/06/13 21:17:34
Sorry if I misunderstand something, but looks like
tbarzic
2013/06/13 21:26:22
ah, sorry, my bad, it was failing to compile, but
| |
54 }; | 78 }; |
55 | 79 |
56 class SystemInfoDisplayApiTest: public ExtensionApiTest { | 80 class SystemInfoDisplayApiTest: public ExtensionApiTest { |
57 public: | 81 public: |
58 SystemInfoDisplayApiTest() {} | 82 SystemInfoDisplayApiTest() {} |
59 virtual ~SystemInfoDisplayApiTest() {} | 83 virtual ~SystemInfoDisplayApiTest() {} |
60 | 84 |
61 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 85 virtual void SetUpOnMainThread() OVERRIDE { |
62 ExtensionApiTest::SetUpCommandLine(command_line); | 86 ExtensionApiTest::SetUpOnMainThread(); |
63 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 87 provider_ = new MockDisplayInfoProvider(); |
88 // The |provider| will be co-owned by the singleton instance. | |
89 DisplayInfoProvider::InitializeForTesting(provider_); | |
64 } | 90 } |
65 | 91 |
66 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 92 virtual void CleanUpOnMainThread() OVERRIDE { |
67 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 93 // Has to be released before the main thread is gone. |
68 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | 94 provider_ = NULL; |
95 ExtensionApiTest::CleanUpOnMainThread(); | |
69 } | 96 } |
70 | 97 |
71 private: | 98 protected: |
72 scoped_ptr<base::MessageLoop> message_loop_; | 99 scoped_refptr<MockDisplayInfoProvider> provider_; |
oshima
2013/06/13 19:12:40
DISALLOW_COPY_AND_ASSIGN
tbarzic
2013/06/13 20:58:15
Done.
| |
73 }; | 100 }; |
74 | 101 |
75 IN_PROC_BROWSER_TEST_F(SystemInfoDisplayApiTest, Display) { | 102 IN_PROC_BROWSER_TEST_F(SystemInfoDisplayApiTest, GetDisplay) { |
76 // The |provider| will be owned by the singleton instance. | |
77 scoped_refptr<MockDisplayInfoProvider> provider = | |
78 new MockDisplayInfoProvider(); | |
79 DisplayInfoProvider::InitializeForTesting(provider); | |
80 ASSERT_TRUE(RunPlatformAppTest("systeminfo/display")) << message_; | 103 ASSERT_TRUE(RunPlatformAppTest("systeminfo/display")) << message_; |
81 } | 104 } |
82 | 105 |
106 #if !defined(OS_CHROMEOS) | |
107 IN_PROC_BROWSER_TEST_F(SystemInfoDisplayApiTest, SetDisplay) { | |
108 scoped_refptr<SystemInfoDisplaySetDisplayUnitInfoFunction> set_info_function( | |
109 new SystemInfoDisplaySetDisplayUnitInfoFunction()); | |
110 | |
111 set_info_function->set_has_callback(true); | |
112 | |
113 EXPECT_EQ("Function available only on ChromeOS.", | |
114 utils::RunFunctionAndReturnError(set_info_function.get(), | |
115 "[\"display_id\", {}]", | |
116 browser())); | |
117 | |
118 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); | |
119 EXPECT_FALSE(set_info); | |
120 } | |
121 #endif // !defined(OS_CHROMEOS) | |
122 | |
123 #if defined(OS_CHROMEOS) | |
124 IN_PROC_BROWSER_TEST_F(SystemInfoDisplayApiTest, SetDisplayNotKioskEnabled) { | |
125 scoped_ptr<base::DictionaryValue> test_extension_value(utils::ParseDictionary( | |
126 "{\n" | |
127 " \"name\": \"Test\",\n" | |
128 " \"version\": \"1.0\",\n" | |
129 " \"app\": {\n" | |
130 " \"background\": {\n" | |
131 " \"scripts\": [\"background.js\"]\n" | |
132 " }\n" | |
133 " }\n" | |
134 "}")); | |
135 scoped_refptr<Extension> test_extension( | |
136 utils::CreateExtension(test_extension_value.get())); | |
137 | |
138 scoped_refptr<SystemInfoDisplaySetDisplayUnitInfoFunction> set_info_function( | |
139 new SystemInfoDisplaySetDisplayUnitInfoFunction()); | |
140 | |
141 set_info_function->set_extension(test_extension.get()); | |
142 set_info_function->set_has_callback(true); | |
143 | |
144 EXPECT_EQ("The extension needs to be kiosk enabled to use the function.", | |
145 utils::RunFunctionAndReturnError(set_info_function.get(), | |
146 "[\"display_id\", {}]", | |
147 browser())); | |
148 | |
149 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); | |
150 EXPECT_FALSE(set_info); | |
151 } | |
152 | |
153 IN_PROC_BROWSER_TEST_F(SystemInfoDisplayApiTest, SetDisplayKioskEnabled) { | |
154 scoped_ptr<base::DictionaryValue> test_extension_value(utils::ParseDictionary( | |
155 "{\n" | |
156 " \"name\": \"Test\",\n" | |
157 " \"version\": \"1.0\",\n" | |
158 " \"app\": {\n" | |
159 " \"background\": {\n" | |
160 " \"scripts\": [\"background.js\"]\n" | |
161 " }\n" | |
162 " },\n" | |
163 " \"kiosk_enabled\": true\n" | |
164 "}")); | |
165 scoped_refptr<Extension> test_extension( | |
166 utils::CreateExtension(test_extension_value.get())); | |
167 | |
168 scoped_refptr<SystemInfoDisplaySetDisplayUnitInfoFunction> set_info_function( | |
169 new SystemInfoDisplaySetDisplayUnitInfoFunction()); | |
170 | |
171 set_info_function->set_has_callback(true); | |
172 set_info_function->set_extension(test_extension.get()); | |
173 | |
174 ASSERT_TRUE(utils::RunFunction( | |
175 set_info_function.get(), | |
176 "[\"display_id\", {\n" | |
177 " \"isPrimary\": true,\n" | |
178 " \"mirroringSourceId\": \"mirroringId\",\n" | |
179 " \"boundsOriginX\": 100,\n" | |
180 " \"boundsOriginY\": 200,\n" | |
181 " \"rotation\": 90,\n" | |
182 " \"overscan\": {\"left\": 1, \"top\": 2, \"right\": 3, \"bottom\": 4}\n" | |
183 "}]", | |
184 browser(), | |
185 utils::NONE)); | |
186 | |
187 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); | |
188 ASSERT_TRUE(set_info); | |
189 EXPECT_TRUE(utils::GetBoolean(set_info.get(), "isPrimary")); | |
190 EXPECT_EQ("mirroringId", | |
191 utils::GetString(set_info.get(), "mirroringSourceId")); | |
192 EXPECT_EQ(100, utils::GetInteger(set_info.get(), "boundsOriginX")); | |
193 EXPECT_EQ(200, utils::GetInteger(set_info.get(), "boundsOriginY")); | |
194 EXPECT_EQ(90, utils::GetInteger(set_info.get(), "rotation")); | |
195 base::DictionaryValue* overscan; | |
196 ASSERT_TRUE(set_info->GetDictionary("overscan", &overscan)); | |
197 EXPECT_EQ(1, utils::GetInteger(overscan, "left")); | |
198 EXPECT_EQ(2, utils::GetInteger(overscan, "top")); | |
199 EXPECT_EQ(3, utils::GetInteger(overscan, "right")); | |
200 EXPECT_EQ(4, utils::GetInteger(overscan, "bottom")); | |
201 | |
202 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); | |
203 } | |
204 #endif // defined(OS_CHROMEOS) | |
205 | |
83 } // namespace extensions | 206 } // namespace extensions |
OLD | NEW |