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

Side by Side Diff: chrome/browser/extensions/app_background_page_apitest.cc

Issue 2847313002: Update some host_resolver()->AddRules in chrome/browser. (Closed)
Patch Set: Created 3 years, 7 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 (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 4
5 #include "base/location.h" 5 #include "base/location.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 using extensions::Extension; 46 using extensions::Extension;
47 47
48 class AppBackgroundPageApiTest : public ExtensionApiTest { 48 class AppBackgroundPageApiTest : public ExtensionApiTest {
49 public: 49 public:
50 void SetUpCommandLine(base::CommandLine* command_line) override { 50 void SetUpCommandLine(base::CommandLine* command_line) override {
51 ExtensionApiTest::SetUpCommandLine(command_line); 51 ExtensionApiTest::SetUpCommandLine(command_line);
52 command_line->AppendSwitch(switches::kDisablePopupBlocking); 52 command_line->AppendSwitch(switches::kDisablePopupBlocking);
53 command_line->AppendSwitch(extensions::switches::kAllowHTTPBackgroundPage); 53 command_line->AppendSwitch(extensions::switches::kAllowHTTPBackgroundPage);
54 } 54 }
55 55
56 void SetUpOnMainThread() override {
57 ExtensionApiTest::SetUpOnMainThread();
58 host_resolver()->AddRule("*", "127.0.0.1");
59 ASSERT_TRUE(StartEmbeddedTestServer());
60 }
61
56 bool CreateApp(const std::string& app_manifest, 62 bool CreateApp(const std::string& app_manifest,
57 base::FilePath* app_dir) { 63 base::FilePath* app_dir) {
58 base::ThreadRestrictions::ScopedAllowIO allow_io; 64 base::ThreadRestrictions::ScopedAllowIO allow_io;
59 if (!app_dir_.CreateUniqueTempDir()) { 65 if (!app_dir_.CreateUniqueTempDir()) {
60 LOG(ERROR) << "Unable to create a temporary directory."; 66 LOG(ERROR) << "Unable to create a temporary directory.";
61 return false; 67 return false;
62 } 68 }
63 base::FilePath manifest_path = 69 base::FilePath manifest_path =
64 app_dir_.GetPath().AppendASCII("manifest.json"); 70 app_dir_.GetPath().AppendASCII("manifest.json");
65 int bytes_written = base::WriteFile(manifest_path, 71 int bytes_written = base::WriteFile(manifest_path,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } // namespace 153 } // namespace
148 154
149 // Disable on Mac only. http://crbug.com/95139 155 // Disable on Mac only. http://crbug.com/95139
150 #if defined(OS_MACOSX) 156 #if defined(OS_MACOSX)
151 #define MAYBE_Basic DISABLED_Basic 157 #define MAYBE_Basic DISABLED_Basic
152 #else 158 #else
153 #define MAYBE_Basic Basic 159 #define MAYBE_Basic Basic
154 #endif 160 #endif
155 161
156 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) { 162 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) {
157 host_resolver()->AddRule("a.com", "127.0.0.1");
158 ASSERT_TRUE(StartEmbeddedTestServer());
159
160 std::string app_manifest = base::StringPrintf( 163 std::string app_manifest = base::StringPrintf(
161 "{" 164 "{"
162 " \"name\": \"App\"," 165 " \"name\": \"App\","
163 " \"version\": \"0.1\"," 166 " \"version\": \"0.1\","
164 " \"manifest_version\": 2," 167 " \"manifest_version\": 2,"
165 " \"app\": {" 168 " \"app\": {"
166 " \"urls\": [" 169 " \"urls\": ["
167 " \"http://a.com/\"" 170 " \"http://a.com/\""
168 " ]," 171 " ],"
169 " \"launch\": {" 172 " \"launch\": {"
(...skipping 10 matching lines...) Expand all
180 // Background mode should not be active until a background page is created. 183 // Background mode should not be active until a background page is created.
181 ASSERT_TRUE(WaitForBackgroundMode(false)); 184 ASSERT_TRUE(WaitForBackgroundMode(false));
182 ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_; 185 ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_;
183 // The test closes the background contents, so we should fall back to no 186 // The test closes the background contents, so we should fall back to no
184 // background mode at the end. 187 // background mode at the end.
185 ASSERT_TRUE(WaitForBackgroundMode(false)); 188 ASSERT_TRUE(WaitForBackgroundMode(false));
186 } 189 }
187 190
188 // Crashy, http://crbug.com/69215. 191 // Crashy, http://crbug.com/69215.
189 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_LacksPermission) { 192 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_LacksPermission) {
190 host_resolver()->AddRule("a.com", "127.0.0.1");
191 ASSERT_TRUE(StartEmbeddedTestServer());
192
193 std::string app_manifest = base::StringPrintf( 193 std::string app_manifest = base::StringPrintf(
194 "{" 194 "{"
195 " \"name\": \"App\"," 195 " \"name\": \"App\","
196 " \"version\": \"0.1\"," 196 " \"version\": \"0.1\","
197 " \"manifest_version\": 2," 197 " \"manifest_version\": 2,"
198 " \"app\": {" 198 " \"app\": {"
199 " \"urls\": [" 199 " \"urls\": ["
200 " \"http://a.com/\"" 200 " \"http://a.com/\""
201 " ]," 201 " ],"
202 " \"launch\": {" 202 " \"launch\": {"
203 " \"web_url\": \"http://a.com:%u/\"" 203 " \"web_url\": \"http://a.com:%u/\""
204 " }" 204 " }"
205 " }" 205 " }"
206 "}", 206 "}",
207 embedded_test_server()->port()); 207 embedded_test_server()->port());
208 208
209 base::FilePath app_dir; 209 base::FilePath app_dir;
210 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); 210 ASSERT_TRUE(CreateApp(app_manifest, &app_dir));
211 ASSERT_TRUE(LoadExtension(app_dir)); 211 ASSERT_TRUE(LoadExtension(app_dir));
212 ASSERT_TRUE(RunExtensionTest("app_background_page/lacks_permission")) 212 ASSERT_TRUE(RunExtensionTest("app_background_page/lacks_permission"))
213 << message_; 213 << message_;
214 ASSERT_TRUE(WaitForBackgroundMode(false)); 214 ASSERT_TRUE(WaitForBackgroundMode(false));
215 } 215 }
216 216
217 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { 217 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) {
218 host_resolver()->AddRule("a.com", "127.0.0.1");
219 ASSERT_TRUE(StartEmbeddedTestServer());
220
221 std::string app_manifest = base::StringPrintf( 218 std::string app_manifest = base::StringPrintf(
222 "{" 219 "{"
223 " \"name\": \"App\"," 220 " \"name\": \"App\","
224 " \"version\": \"0.1\"," 221 " \"version\": \"0.1\","
225 " \"manifest_version\": 2," 222 " \"manifest_version\": 2,"
226 " \"app\": {" 223 " \"app\": {"
227 " \"urls\": [" 224 " \"urls\": ["
228 " \"http://a.com/\"" 225 " \"http://a.com/\""
229 " ]," 226 " ],"
230 " \"launch\": {" 227 " \"launch\": {"
(...skipping 29 matching lines...) Expand all
260 // happen when window.open creates a background page that switches 257 // happen when window.open creates a background page that switches
261 // RenderViewHosts. See http://crbug.com/165138. 258 // RenderViewHosts. See http://crbug.com/165138.
262 chrome::ShowTaskManager(browser()); 259 chrome::ShowTaskManager(browser());
263 260
264 // Make sure that no BackgroundContentses get deleted (a signal that repeated 261 // Make sure that no BackgroundContentses get deleted (a signal that repeated
265 // window.open calls recreate instances, instead of being no-ops). 262 // window.open calls recreate instances, instead of being no-ops).
266 content::TestNotificationTracker background_deleted_tracker; 263 content::TestNotificationTracker background_deleted_tracker;
267 background_deleted_tracker.ListenFor( 264 background_deleted_tracker.ListenFor(
268 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, 265 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED,
269 content::Source<Profile>(browser()->profile())); 266 content::Source<Profile>(browser()->profile()));
270
271 host_resolver()->AddRule("a.com", "127.0.0.1");
272 ASSERT_TRUE(StartEmbeddedTestServer());
273
274 std::string app_manifest = base::StringPrintf( 267 std::string app_manifest = base::StringPrintf(
275 "{" 268 "{"
276 " \"name\": \"App\"," 269 " \"name\": \"App\","
277 " \"version\": \"0.1\"," 270 " \"version\": \"0.1\","
278 " \"manifest_version\": 2," 271 " \"manifest_version\": 2,"
279 " \"app\": {" 272 " \"app\": {"
280 " \"urls\": [" 273 " \"urls\": ["
281 " \"http://a.com/\"" 274 " \"http://a.com/\""
282 " ]," 275 " ],"
283 " \"launch\": {" 276 " \"launch\": {"
(...skipping 21 matching lines...) Expand all
305 // And after it runs there should be a background page. 298 // And after it runs there should be a background page.
306 ASSERT_TRUE( 299 ASSERT_TRUE(
307 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> 300 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
308 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); 301 GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
309 302
310 EXPECT_EQ(0u, background_deleted_tracker.size()); 303 EXPECT_EQ(0u, background_deleted_tracker.size());
311 UnloadExtension(extension->id()); 304 UnloadExtension(extension->id());
312 } 305 }
313 306
314 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { 307 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) {
315 host_resolver()->AddRule("a.com", "127.0.0.1");
316 ASSERT_TRUE(StartEmbeddedTestServer());
317
318 std::string app_manifest = base::StringPrintf( 308 std::string app_manifest = base::StringPrintf(
319 "{" 309 "{"
320 " \"name\": \"App\"," 310 " \"name\": \"App\","
321 " \"version\": \"0.1\"," 311 " \"version\": \"0.1\","
322 " \"manifest_version\": 2," 312 " \"manifest_version\": 2,"
323 " \"app\": {" 313 " \"app\": {"
324 " \"urls\": [" 314 " \"urls\": ["
325 " \"http://a.com/\"" 315 " \"http://a.com/\""
326 " ]," 316 " ],"
327 " \"launch\": {" 317 " \"launch\": {"
(...skipping 17 matching lines...) Expand all
345 const Extension* extension = GetSingleLoadedExtension(); 335 const Extension* extension = GetSingleLoadedExtension();
346 ASSERT_TRUE( 336 ASSERT_TRUE(
347 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> 337 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
348 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); 338 GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
349 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) << 339 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) <<
350 message_; 340 message_;
351 UnloadExtension(extension->id()); 341 UnloadExtension(extension->id());
352 } 342 }
353 343
354 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { 344 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) {
355 host_resolver()->AddRule("a.com", "127.0.0.1");
356 ASSERT_TRUE(StartEmbeddedTestServer());
357
358 std::string app_manifest = base::StringPrintf( 345 std::string app_manifest = base::StringPrintf(
359 "{" 346 "{"
360 " \"name\": \"App\"," 347 " \"name\": \"App\","
361 " \"version\": \"0.1\"," 348 " \"version\": \"0.1\","
362 " \"manifest_version\": 2," 349 " \"manifest_version\": 2,"
363 " \"app\": {" 350 " \"app\": {"
364 " \"urls\": [" 351 " \"urls\": ["
365 " \"http://a.com/\"" 352 " \"http://a.com/\""
366 " ]," 353 " ],"
367 " \"launch\": {" 354 " \"launch\": {"
368 " \"web_url\": \"http://a.com:%u/\"" 355 " \"web_url\": \"http://a.com:%u/\""
369 " }" 356 " }"
370 " }," 357 " },"
371 " \"permissions\": [\"background\"]" 358 " \"permissions\": [\"background\"]"
372 "}", 359 "}",
373 embedded_test_server()->port()); 360 embedded_test_server()->port());
374 361
375 base::FilePath app_dir; 362 base::FilePath app_dir;
376 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); 363 ASSERT_TRUE(CreateApp(app_manifest, &app_dir));
377 ASSERT_TRUE(LoadExtension(app_dir)); 364 ASSERT_TRUE(LoadExtension(app_dir));
378 const Extension* extension = GetSingleLoadedExtension(); 365 const Extension* extension = GetSingleLoadedExtension();
379 ASSERT_TRUE(RunExtensionTest("app_background_page/two_pages")) << message_; 366 ASSERT_TRUE(RunExtensionTest("app_background_page/two_pages")) << message_;
380 UnloadExtension(extension->id()); 367 UnloadExtension(extension->id());
381 } 368 }
382 369
383 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) { 370 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) {
384 host_resolver()->AddRule("a.com", "127.0.0.1");
385 ASSERT_TRUE(StartEmbeddedTestServer());
386
387 std::string app_manifest = base::StringPrintf( 371 std::string app_manifest = base::StringPrintf(
388 "{" 372 "{"
389 " \"name\": \"App\"," 373 " \"name\": \"App\","
390 " \"version\": \"0.1\"," 374 " \"version\": \"0.1\","
391 " \"manifest_version\": 2," 375 " \"manifest_version\": 2,"
392 " \"app\": {" 376 " \"app\": {"
393 " \"urls\": [" 377 " \"urls\": ["
394 " \"http://a.com/\"" 378 " \"http://a.com/\""
395 " ]," 379 " ],"
396 " \"launch\": {" 380 " \"launch\": {"
(...skipping 12 matching lines...) Expand all
409 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); 393 ASSERT_TRUE(CreateApp(app_manifest, &app_dir));
410 ASSERT_TRUE(LoadExtension(app_dir)); 394 ASSERT_TRUE(LoadExtension(app_dir));
411 const Extension* extension = GetSingleLoadedExtension(); 395 const Extension* extension = GetSingleLoadedExtension();
412 ASSERT_TRUE(RunExtensionTest("app_background_page/two_with_manifest")) << 396 ASSERT_TRUE(RunExtensionTest("app_background_page/two_with_manifest")) <<
413 message_; 397 message_;
414 UnloadExtension(extension->id()); 398 UnloadExtension(extension->id());
415 } 399 }
416 400
417 // Times out occasionally -- see crbug.com/108493 401 // Times out occasionally -- see crbug.com/108493
418 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) { 402 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) {
419 host_resolver()->AddRule("a.com", "127.0.0.1");
420 ASSERT_TRUE(StartEmbeddedTestServer());
421
422 std::string app_manifest = base::StringPrintf( 403 std::string app_manifest = base::StringPrintf(
423 "{" 404 "{"
424 " \"name\": \"App\"," 405 " \"name\": \"App\","
425 " \"version\": \"0.1\"," 406 " \"version\": \"0.1\","
426 " \"manifest_version\": 2," 407 " \"manifest_version\": 2,"
427 " \"app\": {" 408 " \"app\": {"
428 " \"urls\": [" 409 " \"urls\": ["
429 " \"http://a.com/\"" 410 " \"http://a.com/\""
430 " ]," 411 " ],"
431 " \"launch\": {" 412 " \"launch\": {"
432 " \"web_url\": \"http://a.com:%u/\"" 413 " \"web_url\": \"http://a.com:%u/\""
433 " }" 414 " }"
434 " }," 415 " },"
435 " \"background\": { \"page\": \"http://a.com:%u/extensions/api_test/" 416 " \"background\": { \"page\": \"http://a.com:%u/extensions/api_test/"
436 "app_background_page/bg_open/bg_open_bg.html\" }," 417 "app_background_page/bg_open/bg_open_bg.html\" },"
437 " \"permissions\": [\"background\"]" 418 " \"permissions\": [\"background\"]"
438 "}", 419 "}",
439 embedded_test_server()->port(), 420 embedded_test_server()->port(),
440 embedded_test_server()->port()); 421 embedded_test_server()->port());
441 422
442 base::FilePath app_dir; 423 base::FilePath app_dir;
443 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); 424 ASSERT_TRUE(CreateApp(app_manifest, &app_dir));
444 ASSERT_TRUE(LoadExtension(app_dir)); 425 ASSERT_TRUE(LoadExtension(app_dir));
445 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; 426 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_;
446 } 427 }
447 428
448 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) { 429 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) {
449 host_resolver()->AddRule("a.com", "127.0.0.1");
450 ASSERT_TRUE(StartEmbeddedTestServer());
451
452 std::string app_manifest = base::StringPrintf( 430 std::string app_manifest = base::StringPrintf(
453 "{" 431 "{"
454 " \"name\": \"App\"," 432 " \"name\": \"App\","
455 " \"version\": \"0.1\"," 433 " \"version\": \"0.1\","
456 " \"manifest_version\": 2," 434 " \"manifest_version\": 2,"
457 " \"app\": {" 435 " \"app\": {"
458 " \"urls\": [" 436 " \"urls\": ["
459 " \"http://a.com/\"" 437 " \"http://a.com/\""
460 " ]," 438 " ],"
461 " \"launch\": {" 439 " \"launch\": {"
(...skipping 23 matching lines...) Expand all
485 // Now close the BackgroundContents. 463 // Now close the BackgroundContents.
486 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_; 464 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_;
487 // Background mode should no longer be active. 465 // Background mode should no longer be active.
488 ASSERT_TRUE(WaitForBackgroundMode(false)); 466 ASSERT_TRUE(WaitForBackgroundMode(false));
489 ASSERT_FALSE( 467 ASSERT_FALSE(
490 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> 468 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())->
491 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); 469 GetAppBackgroundContents(ASCIIToUTF16(extension->id())));
492 } 470 }
493 471
494 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, UnloadExtensionWhileHidden) { 472 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, UnloadExtensionWhileHidden) {
495 host_resolver()->AddRule("a.com", "127.0.0.1");
496 ASSERT_TRUE(StartEmbeddedTestServer());
497
498 std::string app_manifest = base::StringPrintf( 473 std::string app_manifest = base::StringPrintf(
499 "{" 474 "{"
500 " \"name\": \"App\"," 475 " \"name\": \"App\","
501 " \"version\": \"0.1\"," 476 " \"version\": \"0.1\","
502 " \"manifest_version\": 2," 477 " \"manifest_version\": 2,"
503 " \"app\": {" 478 " \"app\": {"
504 " \"urls\": [" 479 " \"urls\": ["
505 " \"http://a.com/\"" 480 " \"http://a.com/\""
506 " ]," 481 " ],"
507 " \"launch\": {" 482 " \"launch\": {"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 ExtensionTestMessageListener ready_listener("ready", true); 569 ExtensionTestMessageListener ready_listener("ready", true);
595 LaunchTestingApp(); 570 LaunchTestingApp();
596 EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); 571 EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
597 572
598 ExtensionTestMessageListener created_listener("created_module:1", false); 573 ExtensionTestMessageListener created_listener("created_module:1", false);
599 ready_listener.Reply("create_module_without_hack"); 574 ready_listener.Reply("create_module_without_hack");
600 EXPECT_TRUE(created_listener.WaitUntilSatisfied()); 575 EXPECT_TRUE(created_listener.WaitUntilSatisfied());
601 } 576 }
602 577
603 #endif // !defined(DISABLE_NACL) 578 #endif // !defined(DISABLE_NACL)
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/extensions/app_process_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698