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

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

Issue 10807047: Create content\public\test\test_utils.h to hold common test classes that are used by unit and brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // are set up with the defaults. 108 // are set up with the defaults.
109 service->extension_prefs()->OnExtensionInstalled( 109 service->extension_prefs()->OnExtensionInstalled(
110 extension, Extension::ENABLED, false, 110 extension, Extension::ENABLED, false,
111 StringOrdinal::CreateInitialOrdinal()); 111 StringOrdinal::CreateInitialOrdinal());
112 112
113 // Toggling incognito or file access will reload the extension, so wait for 113 // Toggling incognito or file access will reload the extension, so wait for
114 // the reload and grab the new extension instance. The default state is 114 // the reload and grab the new extension instance. The default state is
115 // incognito disabled and file access enabled, so we don't wait in those 115 // incognito disabled and file access enabled, so we don't wait in those
116 // cases. 116 // cases.
117 { 117 {
118 ui_test_utils::WindowedNotificationObserver load_signal( 118 content::WindowedNotificationObserver load_signal(
119 chrome::NOTIFICATION_EXTENSION_LOADED, 119 chrome::NOTIFICATION_EXTENSION_LOADED,
120 content::Source<Profile>(browser()->profile())); 120 content::Source<Profile>(browser()->profile()));
121 CHECK(!service->IsIncognitoEnabled(extension_id)); 121 CHECK(!service->IsIncognitoEnabled(extension_id));
122 122
123 if (incognito_enabled) { 123 if (incognito_enabled) {
124 service->SetIsIncognitoEnabled(extension_id, incognito_enabled); 124 service->SetIsIncognitoEnabled(extension_id, incognito_enabled);
125 load_signal.Wait(); 125 load_signal.Wait();
126 extension = service->GetExtensionById(extension_id, false); 126 extension = service->GetExtensionById(extension_id, false);
127 CHECK(extension) << extension_id << " not found after reloading."; 127 CHECK(extension) << extension_id << " not found after reloading.";
128 } 128 }
129 } 129 }
130 130
131 { 131 {
132 ui_test_utils::WindowedNotificationObserver load_signal( 132 content::WindowedNotificationObserver load_signal(
133 chrome::NOTIFICATION_EXTENSION_LOADED, 133 chrome::NOTIFICATION_EXTENSION_LOADED,
134 content::Source<Profile>(browser()->profile())); 134 content::Source<Profile>(browser()->profile()));
135 CHECK(service->AllowFileAccess(extension)); 135 CHECK(service->AllowFileAccess(extension));
136 136
137 if (!fileaccess_enabled) { 137 if (!fileaccess_enabled) {
138 service->SetAllowFileAccess(extension, fileaccess_enabled); 138 service->SetAllowFileAccess(extension, fileaccess_enabled);
139 load_signal.Wait(); 139 load_signal.Wait();
140 extension = service->GetExtensionById(extension_id, false); 140 extension = service->GetExtensionById(extension_id, false);
141 CHECK(extension) << extension_id << " not found after reloading."; 141 CHECK(extension) << extension_id << " not found after reloading.";
142 } 142 }
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ui_test_utils::RegisterAndWait(this, 483 ui_test_utils::RegisterAndWait(this,
484 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 484 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
485 content::NotificationService::AllSources()); 485 content::NotificationService::AllSources());
486 return crx_installers_done_observed_ == (before + 1); 486 return crx_installers_done_observed_ == (before + 1);
487 } 487 }
488 488
489 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, 489 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
490 const GURL& url, 490 const GURL& url,
491 bool newtab_process_should_equal_opener, 491 bool newtab_process_should_equal_opener,
492 content::WebContents** newtab_result) { 492 content::WebContents** newtab_result) {
493 ui_test_utils::WindowedNotificationObserver observer( 493 content::WindowedNotificationObserver observer(
494 content::NOTIFICATION_LOAD_STOP, 494 content::NOTIFICATION_LOAD_STOP,
495 content::NotificationService::AllSources()); 495 content::NotificationService::AllSources());
496 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 496 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
497 contents->GetRenderViewHost(), L"", 497 contents->GetRenderViewHost(), L"",
498 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); 498 L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
499 499
500 // The above window.open call is not user-initiated, so it will create 500 // The above window.open call is not user-initiated, so it will create
501 // a popup window instead of a new tab in current window. 501 // a popup window instead of a new tab in current window.
502 // The stop notification will come from the new tab. 502 // The stop notification will come from the new tab.
503 observer.Wait(); 503 observer.Wait();
504 content::NavigationController* controller = 504 content::NavigationController* controller =
505 content::Source<content::NavigationController>(observer.source()).ptr(); 505 content::Source<content::NavigationController>(observer.source()).ptr();
506 content::WebContents* newtab = controller->GetWebContents(); 506 content::WebContents* newtab = controller->GetWebContents();
507 ASSERT_TRUE(newtab); 507 ASSERT_TRUE(newtab);
508 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); 508 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL());
509 if (newtab_process_should_equal_opener) 509 if (newtab_process_should_equal_opener)
510 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 510 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
511 else 511 else
512 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 512 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
513 513
514 if (newtab_result) 514 if (newtab_result)
515 *newtab_result = newtab; 515 *newtab_result = newtab;
516 } 516 }
517 517
518 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, 518 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
519 const GURL& url) { 519 const GURL& url) {
520 bool result = false; 520 bool result = false;
521 ui_test_utils::WindowedNotificationObserver observer( 521 content::WindowedNotificationObserver observer(
522 content::NOTIFICATION_LOAD_STOP, 522 content::NOTIFICATION_LOAD_STOP,
523 content::NotificationService::AllSources()); 523 content::NotificationService::AllSources());
524 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 524 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
525 contents->GetRenderViewHost(), L"", 525 contents->GetRenderViewHost(), L"",
526 L"window.addEventListener('unload', function() {" 526 L"window.addEventListener('unload', function() {"
527 L" window.domAutomationController.send(true);" 527 L" window.domAutomationController.send(true);"
528 L"}, false);" 528 L"}, false);"
529 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", 529 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
530 &result)); 530 &result));
531 ASSERT_TRUE(result); 531 ASSERT_TRUE(result);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 case content::NOTIFICATION_LOAD_STOP: 631 case content::NOTIFICATION_LOAD_STOP:
632 VLOG(1) << "Got LOAD_STOP notification."; 632 VLOG(1) << "Got LOAD_STOP notification.";
633 MessageLoopForUI::current()->Quit(); 633 MessageLoopForUI::current()->Quit();
634 break; 634 break;
635 635
636 default: 636 default:
637 NOTREACHED(); 637 NOTREACHED();
638 break; 638 break;
639 } 639 }
640 } 640 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/content_script_apitest.cc ('k') | chrome/browser/extensions/extension_crash_recovery_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698