Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1241)

Side by Side Diff: extensions/browser/api/system_display/system_display_apitest.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 EXPECT_FALSE(set_info_value_); 85 EXPECT_FALSE(set_info_value_);
86 set_info_value_ = params.ToValue(); 86 set_info_value_ = params.ToValue();
87 set_info_display_id_ = display_id; 87 set_info_display_id_ = display_id;
88 return true; 88 return true;
89 } 89 }
90 90
91 void EnableUnifiedDesktop(bool enable) override { 91 void EnableUnifiedDesktop(bool enable) override {
92 unified_desktop_enabled_ = enable; 92 unified_desktop_enabled_ = enable;
93 } 93 }
94 94
95 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { 95 std::unique_ptr<base::DictionaryValue> GetSetInfoValue() {
96 return std::move(set_info_value_); 96 return std::move(set_info_value_);
97 } 97 }
98 98
99 std::string GetSetInfoDisplayId() const { return set_info_display_id_; } 99 std::string GetSetInfoDisplayId() const { return set_info_display_id_; }
100 100
101 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } 101 bool unified_desktop_enabled() const { return unified_desktop_enabled_; }
102 102
103 private: 103 private:
104 // Update the content of the |unit| obtained for |display| using 104 // Update the content of the |unit| obtained for |display| using
105 // platform specific method. 105 // platform specific method.
(...skipping 11 matching lines...) Expand all
117 unit->dpi_x = 96.0; 117 unit->dpi_x = 96.0;
118 unit->dpi_y = 96.0; 118 unit->dpi_y = 96.0;
119 if (id == 0) { 119 if (id == 0) {
120 unit->overscan.left = 20; 120 unit->overscan.left = 20;
121 unit->overscan.top = 40; 121 unit->overscan.top = 40;
122 unit->overscan.right = 60; 122 unit->overscan.right = 60;
123 unit->overscan.bottom = 80; 123 unit->overscan.bottom = 80;
124 } 124 }
125 } 125 }
126 126
127 scoped_ptr<base::DictionaryValue> set_info_value_; 127 std::unique_ptr<base::DictionaryValue> set_info_value_;
128 std::string set_info_display_id_; 128 std::string set_info_display_id_;
129 bool unified_desktop_enabled_ = false; 129 bool unified_desktop_enabled_ = false;
130 130
131 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); 131 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider);
132 }; 132 };
133 133
134 class SystemDisplayApiTest : public ShellApiTest { 134 class SystemDisplayApiTest : public ShellApiTest {
135 public: 135 public:
136 SystemDisplayApiTest() 136 SystemDisplayApiTest()
137 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {} 137 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {}
138 138
139 ~SystemDisplayApiTest() override {} 139 ~SystemDisplayApiTest() override {}
140 140
141 void SetUpOnMainThread() override { 141 void SetUpOnMainThread() override {
142 ShellApiTest::SetUpOnMainThread(); 142 ShellApiTest::SetUpOnMainThread();
143 ANNOTATE_LEAKING_OBJECT_PTR(gfx::Screen::GetScreen()); 143 ANNOTATE_LEAKING_OBJECT_PTR(gfx::Screen::GetScreen());
144 gfx::Screen::SetScreenInstance(screen_.get()); 144 gfx::Screen::SetScreenInstance(screen_.get());
145 DisplayInfoProvider::InitializeForTesting(provider_.get()); 145 DisplayInfoProvider::InitializeForTesting(provider_.get());
146 } 146 }
147 147
148 protected: 148 protected:
149 scoped_ptr<MockDisplayInfoProvider> provider_; 149 std::unique_ptr<MockDisplayInfoProvider> provider_;
150 scoped_ptr<gfx::Screen> screen_; 150 std::unique_ptr<gfx::Screen> screen_;
151 151
152 private: 152 private:
153 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); 153 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest);
154 }; 154 };
155 155
156 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { 156 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) {
157 ASSERT_TRUE(RunAppTest("system/display")) << message_; 157 ASSERT_TRUE(RunAppTest("system/display")) << message_;
158 } 158 }
159 159
160 #if !defined(OS_CHROMEOS) 160 #if !defined(OS_CHROMEOS)
161 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { 161 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) {
162 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( 162 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function(
163 new SystemDisplaySetDisplayPropertiesFunction()); 163 new SystemDisplaySetDisplayPropertiesFunction());
164 164
165 set_info_function->set_has_callback(true); 165 set_info_function->set_has_callback(true);
166 166
167 EXPECT_EQ( 167 EXPECT_EQ(
168 "Function available only on ChromeOS.", 168 "Function available only on ChromeOS.",
169 api_test_utils::RunFunctionAndReturnError( 169 api_test_utils::RunFunctionAndReturnError(
170 set_info_function.get(), "[\"display_id\", {}]", browser_context())); 170 set_info_function.get(), "[\"display_id\", {}]", browser_context()));
171 171
172 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); 172 std::unique_ptr<base::DictionaryValue> set_info =
173 provider_->GetSetInfoValue();
173 EXPECT_FALSE(set_info); 174 EXPECT_FALSE(set_info);
174 } 175 }
175 #endif // !defined(OS_CHROMEOS) 176 #endif // !defined(OS_CHROMEOS)
176 177
177 #if defined(OS_CHROMEOS) 178 #if defined(OS_CHROMEOS)
178 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { 179 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) {
179 scoped_ptr<base::DictionaryValue> test_extension_value( 180 std::unique_ptr<base::DictionaryValue> test_extension_value(
180 api_test_utils::ParseDictionary( 181 api_test_utils::ParseDictionary("{\n"
181 "{\n" 182 " \"name\": \"Test\",\n"
182 " \"name\": \"Test\",\n" 183 " \"version\": \"1.0\",\n"
183 " \"version\": \"1.0\",\n" 184 " \"app\": {\n"
184 " \"app\": {\n" 185 " \"background\": {\n"
185 " \"background\": {\n" 186 " \"scripts\": [\"background.js\"]\n"
186 " \"scripts\": [\"background.js\"]\n" 187 " }\n"
187 " }\n" 188 " }\n"
188 " }\n" 189 "}"));
189 "}"));
190 scoped_refptr<Extension> test_extension( 190 scoped_refptr<Extension> test_extension(
191 api_test_utils::CreateExtension(test_extension_value.get())); 191 api_test_utils::CreateExtension(test_extension_value.get()));
192 192
193 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( 193 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function(
194 new SystemDisplaySetDisplayPropertiesFunction()); 194 new SystemDisplaySetDisplayPropertiesFunction());
195 195
196 set_info_function->set_extension(test_extension.get()); 196 set_info_function->set_extension(test_extension.get());
197 set_info_function->set_has_callback(true); 197 set_info_function->set_has_callback(true);
198 198
199 EXPECT_EQ( 199 EXPECT_EQ(
200 "The extension needs to be kiosk enabled to use the function.", 200 "The extension needs to be kiosk enabled to use the function.",
201 api_test_utils::RunFunctionAndReturnError( 201 api_test_utils::RunFunctionAndReturnError(
202 set_info_function.get(), "[\"display_id\", {}]", browser_context())); 202 set_info_function.get(), "[\"display_id\", {}]", browser_context()));
203 203
204 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); 204 std::unique_ptr<base::DictionaryValue> set_info =
205 provider_->GetSetInfoValue();
205 EXPECT_FALSE(set_info); 206 EXPECT_FALSE(set_info);
206 } 207 }
207 208
208 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) { 209 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) {
209 scoped_ptr<base::DictionaryValue> test_extension_value( 210 std::unique_ptr<base::DictionaryValue> test_extension_value(
210 api_test_utils::ParseDictionary( 211 api_test_utils::ParseDictionary("{\n"
211 "{\n" 212 " \"name\": \"Test\",\n"
212 " \"name\": \"Test\",\n" 213 " \"version\": \"1.0\",\n"
213 " \"version\": \"1.0\",\n" 214 " \"app\": {\n"
214 " \"app\": {\n" 215 " \"background\": {\n"
215 " \"background\": {\n" 216 " \"scripts\": [\"background.js\"]\n"
216 " \"scripts\": [\"background.js\"]\n" 217 " }\n"
217 " }\n" 218 " },\n"
218 " },\n" 219 " \"kiosk_enabled\": true\n"
219 " \"kiosk_enabled\": true\n" 220 "}"));
220 "}"));
221 scoped_refptr<Extension> test_extension( 221 scoped_refptr<Extension> test_extension(
222 api_test_utils::CreateExtension(test_extension_value.get())); 222 api_test_utils::CreateExtension(test_extension_value.get()));
223 223
224 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( 224 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function(
225 new SystemDisplaySetDisplayPropertiesFunction()); 225 new SystemDisplaySetDisplayPropertiesFunction());
226 226
227 set_info_function->set_has_callback(true); 227 set_info_function->set_has_callback(true);
228 set_info_function->set_extension(test_extension.get()); 228 set_info_function->set_extension(test_extension.get());
229 229
230 ASSERT_TRUE(api_test_utils::RunFunction( 230 ASSERT_TRUE(api_test_utils::RunFunction(
231 set_info_function.get(), 231 set_info_function.get(),
232 "[\"display_id\", {\n" 232 "[\"display_id\", {\n"
233 " \"isPrimary\": true,\n" 233 " \"isPrimary\": true,\n"
234 " \"mirroringSourceId\": \"mirroringId\",\n" 234 " \"mirroringSourceId\": \"mirroringId\",\n"
235 " \"boundsOriginX\": 100,\n" 235 " \"boundsOriginX\": 100,\n"
236 " \"boundsOriginY\": 200,\n" 236 " \"boundsOriginY\": 200,\n"
237 " \"rotation\": 90,\n" 237 " \"rotation\": 90,\n"
238 " \"overscan\": {\"left\": 1, \"top\": 2, \"right\": 3, \"bottom\": 4}\n" 238 " \"overscan\": {\"left\": 1, \"top\": 2, \"right\": 3, \"bottom\": 4}\n"
239 "}]", 239 "}]",
240 browser_context())); 240 browser_context()));
241 241
242 scoped_ptr<base::DictionaryValue> set_info = provider_->GetSetInfoValue(); 242 std::unique_ptr<base::DictionaryValue> set_info =
243 provider_->GetSetInfoValue();
243 ASSERT_TRUE(set_info); 244 ASSERT_TRUE(set_info);
244 EXPECT_TRUE(api_test_utils::GetBoolean(set_info.get(), "isPrimary")); 245 EXPECT_TRUE(api_test_utils::GetBoolean(set_info.get(), "isPrimary"));
245 EXPECT_EQ("mirroringId", 246 EXPECT_EQ("mirroringId",
246 api_test_utils::GetString(set_info.get(), "mirroringSourceId")); 247 api_test_utils::GetString(set_info.get(), "mirroringSourceId"));
247 EXPECT_EQ(100, api_test_utils::GetInteger(set_info.get(), "boundsOriginX")); 248 EXPECT_EQ(100, api_test_utils::GetInteger(set_info.get(), "boundsOriginX"));
248 EXPECT_EQ(200, api_test_utils::GetInteger(set_info.get(), "boundsOriginY")); 249 EXPECT_EQ(200, api_test_utils::GetInteger(set_info.get(), "boundsOriginY"));
249 EXPECT_EQ(90, api_test_utils::GetInteger(set_info.get(), "rotation")); 250 EXPECT_EQ(90, api_test_utils::GetInteger(set_info.get(), "rotation"));
250 base::DictionaryValue* overscan; 251 base::DictionaryValue* overscan;
251 ASSERT_TRUE(set_info->GetDictionary("overscan", &overscan)); 252 ASSERT_TRUE(set_info->GetDictionary("overscan", &overscan));
252 EXPECT_EQ(1, api_test_utils::GetInteger(overscan, "left")); 253 EXPECT_EQ(1, api_test_utils::GetInteger(overscan, "left"));
253 EXPECT_EQ(2, api_test_utils::GetInteger(overscan, "top")); 254 EXPECT_EQ(2, api_test_utils::GetInteger(overscan, "top"));
254 EXPECT_EQ(3, api_test_utils::GetInteger(overscan, "right")); 255 EXPECT_EQ(3, api_test_utils::GetInteger(overscan, "right"));
255 EXPECT_EQ(4, api_test_utils::GetInteger(overscan, "bottom")); 256 EXPECT_EQ(4, api_test_utils::GetInteger(overscan, "bottom"));
256 257
257 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); 258 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId());
258 } 259 }
259 260
260 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) { 261 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) {
261 scoped_ptr<base::DictionaryValue> test_extension_value( 262 std::unique_ptr<base::DictionaryValue> test_extension_value(
262 api_test_utils::ParseDictionary("{\n" 263 api_test_utils::ParseDictionary("{\n"
263 " \"name\": \"Test\",\n" 264 " \"name\": \"Test\",\n"
264 " \"version\": \"1.0\",\n" 265 " \"version\": \"1.0\",\n"
265 " \"app\": {\n" 266 " \"app\": {\n"
266 " \"background\": {\n" 267 " \"background\": {\n"
267 " \"scripts\": [\"background.js\"]\n" 268 " \"scripts\": [\"background.js\"]\n"
268 " }\n" 269 " }\n"
269 " }\n" 270 " }\n"
270 "}")); 271 "}"));
271 scoped_refptr<Extension> test_extension( 272 scoped_refptr<Extension> test_extension(
(...skipping 21 matching lines...) Expand all
293 enable_unified_function->set_extension(test_extension.get()); 294 enable_unified_function->set_extension(test_extension.get());
294 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), 295 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(),
295 "[false]", browser_context())); 296 "[false]", browser_context()));
296 EXPECT_FALSE(provider_->unified_desktop_enabled()); 297 EXPECT_FALSE(provider_->unified_desktop_enabled());
297 } 298 }
298 } 299 }
299 300
300 #endif // defined(OS_CHROMEOS) 301 #endif // defined(OS_CHROMEOS)
301 302
302 } // namespace extensions 303 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/system_display/system_display_api.cc ('k') | extensions/browser/api/system_info/system_info_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698