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

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

Issue 10412047: Fix flakiness by removing GetLastActive from extension browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch Created 8 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 | Annotate | Revision Log
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 "chrome/browser/extensions/extension_browsertest.h" 5 #include "chrome/browser/extensions/extension_browsertest.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/extensions/app_shortcut_manager.h" 16 #include "chrome/browser/extensions/app_shortcut_manager.h"
16 #include "chrome/browser/extensions/component_loader.h" 17 #include "chrome/browser/extensions/component_loader.h"
17 #include "chrome/browser/extensions/crx_installer.h" 18 #include "chrome/browser/extensions/crx_installer.h"
18 #include "chrome/browser/extensions/extension_creator.h" 19 #include "chrome/browser/extensions/extension_creator.h"
19 #include "chrome/browser/extensions/extension_error_reporter.h" 20 #include "chrome/browser/extensions/extension_error_reporter.h"
20 #include "chrome/browser/extensions/extension_install_ui.h" 21 #include "chrome/browser/extensions/extension_install_ui.h"
21 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/unpacked_installer.h" 23 #include "chrome/browser/extensions/unpacked_installer.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/omnibox/location_bar.h" 27 #include "chrome/browser/ui/omnibox/location_bar.h"
27 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
32 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/notification_registrar.h" 34 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/render_view_host.h" 36 #include "content/public/browser/render_view_host.h"
34 37
35 using extensions::Extension; 38 using extensions::Extension;
36 39
37 ExtensionBrowserTest::ExtensionBrowserTest() 40 ExtensionBrowserTest::ExtensionBrowserTest()
38 : loaded_(false), 41 : loaded_(false),
39 installed_(false), 42 installed_(false),
40 extension_installs_observed_(0), 43 extension_installs_observed_(0),
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (!service->GetExtensionById(extension_id, true)) { 456 if (!service->GetExtensionById(extension_id, true)) {
454 // The extension is already unloaded, presumably due to a crash. 457 // The extension is already unloaded, presumably due to a crash.
455 return true; 458 return true;
456 } 459 }
457 ui_test_utils::RegisterAndWait( 460 ui_test_utils::RegisterAndWait(
458 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 461 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
459 content::NotificationService::AllSources()); 462 content::NotificationService::AllSources());
460 return (service->GetExtensionById(extension_id, true) == NULL); 463 return (service->GetExtensionById(extension_id, true) == NULL);
461 } 464 }
462 465
466 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
467 const GURL& url,
468 bool newtab_process_should_equal_opener,
469 content::WebContents** newtab_result) {
470 ui_test_utils::WindowedNotificationObserver observer(
471 content::NOTIFICATION_LOAD_STOP,
472 content::NotificationService::AllSources());
473 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
474 contents->GetRenderViewHost(), L"",
475 L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
476
477 // The above window.open call is not user-initiated, so it will create
478 // a popup window instead of a new tab in current window.
479 // The stop notification will come from the new tab.
480 observer.Wait();
481 content::NavigationController* controller =
482 content::Source<content::NavigationController>(observer.source()).ptr();
483 content::WebContents* newtab = controller->GetWebContents();
484 ASSERT_TRUE(newtab);
485 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL());
486 if (newtab_process_should_equal_opener)
Matt Perry 2012/05/23 00:56:40 It seems weird to have this special check here. Ca
Charlie Reis 2012/05/23 01:01:20 I suppose I could duplicate it into all the call s
Matt Perry 2012/05/23 01:02:19 OK, nevermind. Since all callers care, let's just
487 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
488 else
489 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
490
491 if (newtab_result)
492 *newtab_result = newtab;
493 }
494
495 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
496 const GURL& url) {
497 bool result = false;
498 ui_test_utils::WindowedNotificationObserver observer(
499 content::NOTIFICATION_LOAD_STOP,
500 content::NotificationService::AllSources());
501 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
502 contents->GetRenderViewHost(), L"",
503 L"window.addEventListener('unload', function() {"
504 L" window.domAutomationController.send(true);"
505 L"}, false);"
506 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
507 &result));
508 ASSERT_TRUE(result);
509 observer.Wait();
510 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL());
511 }
512
463 void ExtensionBrowserTest::Observe( 513 void ExtensionBrowserTest::Observe(
464 int type, 514 int type,
465 const content::NotificationSource& source, 515 const content::NotificationSource& source,
466 const content::NotificationDetails& details) { 516 const content::NotificationDetails& details) {
467 switch (type) { 517 switch (type) {
468 case chrome::NOTIFICATION_EXTENSION_LOADED: 518 case chrome::NOTIFICATION_EXTENSION_LOADED:
469 last_loaded_extension_id_ = 519 last_loaded_extension_id_ =
470 content::Details<const Extension>(details).ptr()->id(); 520 content::Details<const Extension>(details).ptr()->id();
471 VLOG(1) << "Got EXTENSION_LOADED notification."; 521 VLOG(1) << "Got EXTENSION_LOADED notification.";
472 MessageLoopForUI::current()->Quit(); 522 MessageLoopForUI::current()->Quit();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 case content::NOTIFICATION_LOAD_STOP: 587 case content::NOTIFICATION_LOAD_STOP:
538 VLOG(1) << "Got LOAD_STOP notification."; 588 VLOG(1) << "Got LOAD_STOP notification.";
539 MessageLoopForUI::current()->Quit(); 589 MessageLoopForUI::current()->Quit();
540 break; 590 break;
541 591
542 default: 592 default:
543 NOTREACHED(); 593 NOTREACHED();
544 break; 594 break;
545 } 595 }
546 } 596 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_browsertests_misc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698