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

Side by Side Diff: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc

Issue 2441543004: Refactor BrowserActivationWaiter as test support and move PopupBlockerBrowserTest to interactive_ui… (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 19 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h" 21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_finder.h" 22 #include "chrome/browser/ui/browser_finder.h"
23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/location_bar/location_bar.h" 24 #include "chrome/browser/ui/location_bar/location_bar.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
30 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
31 #include "chrome/test/base/search_test_utils.h" 30 #include "chrome/test/base/search_test_utils.h"
32 #include "chrome/test/base/ui_test_utils.h" 31 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/app_modal/javascript_app_modal_dialog.h" 32 #include "components/app_modal/javascript_app_modal_dialog.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 96 }
98 97
99 void WebContentsDestroyed() override { close_loop_.Quit(); } 98 void WebContentsDestroyed() override { close_loop_.Quit(); }
100 99
101 private: 100 private:
102 base::RunLoop close_loop_; 101 base::RunLoop close_loop_;
103 102
104 DISALLOW_COPY_AND_ASSIGN(CloseObserver); 103 DISALLOW_COPY_AND_ASSIGN(CloseObserver);
105 }; 104 };
106 105
107 class BrowserActivationObserver : public chrome::BrowserListObserver {
108 public:
109 BrowserActivationObserver()
110 : browser_(chrome::FindLastActive()), observed_(false) {
111 BrowserList::AddObserver(this);
112 }
113 ~BrowserActivationObserver() override { BrowserList::RemoveObserver(this); }
114
115 void WaitForActivation() {
116 if (observed_)
117 return;
118 message_loop_runner_ = new content::MessageLoopRunner;
119 message_loop_runner_->Run();
120 }
121
122 private:
123 // chrome::BrowserListObserver:
124 void OnBrowserSetLastActive(Browser* browser) override {
125 if (browser == browser_)
126 return;
127 observed_ = true;
128 if (message_loop_runner_.get() && message_loop_runner_->loop_running())
129 message_loop_runner_->Quit();
130 }
131
132 Browser* browser_;
133 bool observed_;
134 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
135
136 DISALLOW_COPY_AND_ASSIGN(BrowserActivationObserver);
137 };
138
139 class PopupBlockerBrowserTest : public InProcessBrowserTest { 106 class PopupBlockerBrowserTest : public InProcessBrowserTest {
140 public: 107 public:
141 PopupBlockerBrowserTest() {} 108 PopupBlockerBrowserTest() {}
142 ~PopupBlockerBrowserTest() override {} 109 ~PopupBlockerBrowserTest() override {}
143 110
144 void SetUpOnMainThread() override { 111 void SetUpOnMainThread() override {
145 InProcessBrowserTest::SetUpOnMainThread(); 112 InProcessBrowserTest::SetUpOnMainThread();
146 113
147 host_resolver()->AddRule("*", "127.0.0.1"); 114 host_resolver()->AddRule("*", "127.0.0.1");
148 ASSERT_TRUE(embedded_test_server()->Start()); 115 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 510
544 // Showing an alert will raise the tab over the popup. 511 // Showing an alert will raise the tab over the popup.
545 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); 512 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
546 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); 513 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
547 514
548 // Verify that after the dialog was closed, the popup is in front again. 515 // Verify that after the dialog was closed, the popup is in front again.
549 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); 516 ASSERT_TRUE(dialog->IsJavaScriptModalDialog());
550 app_modal::JavaScriptAppModalDialog* js_dialog = 517 app_modal::JavaScriptAppModalDialog* js_dialog =
551 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); 518 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
552 519
553 BrowserActivationObserver activation_observer; 520 ui_test_utils::BrowserActivationWaiter waiter(popup_browser);
554 js_dialog->native_dialog()->AcceptAppModalDialog(); 521 js_dialog->native_dialog()->AcceptAppModalDialog();
555 522 waiter.WaitForActivation();
556 if (popup_browser != chrome::FindLastActive())
557 activation_observer.WaitForActivation();
558 ASSERT_EQ(popup_browser, chrome::FindLastActive()); 523 ASSERT_EQ(popup_browser, chrome::FindLastActive());
559 } 524 }
560 525
561 // Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab. 526 // Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab.
562 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) { 527 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) {
563 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 528 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
564 529
565 GURL url(embedded_test_server()->GetURL( 530 GURL url(embedded_test_server()->GetURL(
566 "/popup_blocker/popup-simulated-click-on-anchor.html")); 531 "/popup_blocker/popup-simulated-click-on-anchor.html"));
567 ui_test_utils::NavigateToURL(browser(), url); 532 ui_test_utils::NavigateToURL(browser(), url);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 573
609 wait_for_new_tab.Wait(); 574 wait_for_new_tab.Wait();
610 575
611 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); 576 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile()));
612 ASSERT_EQ(2, browser()->tab_strip_model()->count()); 577 ASSERT_EQ(2, browser()->tab_strip_model()->count());
613 // Check that we create the background tab. 578 // Check that we create the background tab.
614 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); 579 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
615 } 580 }
616 581
617 } // namespace 582 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698