| OLD | NEW |
| 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" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void WebContentsDestroyed() override { close_loop_.Quit(); } | 100 void WebContentsDestroyed() override { close_loop_.Quit(); } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 base::RunLoop close_loop_; | 103 base::RunLoop close_loop_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(CloseObserver); | 105 DISALLOW_COPY_AND_ASSIGN(CloseObserver); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 class BrowserActivationObserver : public chrome::BrowserListObserver { | 108 class BrowserActivationObserver : public chrome::BrowserListObserver { |
| 109 public: | 109 public: |
| 110 explicit BrowserActivationObserver(chrome::HostDesktopType desktop_type) | 110 BrowserActivationObserver() |
| 111 : browser_(chrome::FindLastActiveWithHostDesktopType(desktop_type)), | 111 : browser_(chrome::FindLastActive()), observed_(false) { |
| 112 observed_(false) { | |
| 113 BrowserList::AddObserver(this); | 112 BrowserList::AddObserver(this); |
| 114 } | 113 } |
| 115 ~BrowserActivationObserver() override { BrowserList::RemoveObserver(this); } | 114 ~BrowserActivationObserver() override { BrowserList::RemoveObserver(this); } |
| 116 | 115 |
| 117 void WaitForActivation() { | 116 void WaitForActivation() { |
| 118 if (observed_) | 117 if (observed_) |
| 119 return; | 118 return; |
| 120 message_loop_runner_ = new content::MessageLoopRunner; | 119 message_loop_runner_ = new content::MessageLoopRunner; |
| 121 message_loop_runner_->Run(); | 120 message_loop_runner_->Run(); |
| 122 } | 121 } |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); | 572 embedded_test_server()->GetURL("/popup_blocker/popup-window-open.html")); |
| 574 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 573 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 575 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | 574 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
| 576 ContentSettingsPattern::Wildcard(), | 575 ContentSettingsPattern::Wildcard(), |
| 577 CONTENT_SETTINGS_TYPE_POPUPS, | 576 CONTENT_SETTINGS_TYPE_POPUPS, |
| 578 std::string(), | 577 std::string(), |
| 579 CONTENT_SETTING_ALLOW); | 578 CONTENT_SETTING_ALLOW); |
| 580 | 579 |
| 581 NavigateAndCheckPopupShown(url, ExpectPopup); | 580 NavigateAndCheckPopupShown(url, ExpectPopup); |
| 582 | 581 |
| 583 Browser* popup_browser = | 582 Browser* popup_browser = chrome::FindLastActive(); |
| 584 chrome::FindLastActiveWithHostDesktopType(browser()->host_desktop_type()); | |
| 585 ASSERT_NE(popup_browser, browser()); | 583 ASSERT_NE(popup_browser, browser()); |
| 586 | 584 |
| 587 // Showing an alert will raise the tab over the popup. | 585 // Showing an alert will raise the tab over the popup. |
| 588 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 586 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
| 589 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 587 app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); |
| 590 | 588 |
| 591 // Verify that after the dialog was closed, the popup is in front again. | 589 // Verify that after the dialog was closed, the popup is in front again. |
| 592 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 590 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); |
| 593 app_modal::JavaScriptAppModalDialog* js_dialog = | 591 app_modal::JavaScriptAppModalDialog* js_dialog = |
| 594 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 592 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
| 595 | 593 |
| 596 BrowserActivationObserver activation_observer(browser()->host_desktop_type()); | 594 BrowserActivationObserver activation_observer; |
| 597 js_dialog->native_dialog()->AcceptAppModalDialog(); | 595 js_dialog->native_dialog()->AcceptAppModalDialog(); |
| 598 | 596 |
| 599 if (popup_browser != chrome::FindLastActiveWithHostDesktopType( | 597 if (popup_browser != chrome::FindLastActive()) |
| 600 popup_browser->host_desktop_type())) { | |
| 601 activation_observer.WaitForActivation(); | 598 activation_observer.WaitForActivation(); |
| 602 } | 599 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
| 603 ASSERT_EQ(popup_browser, chrome::FindLastActiveWithHostDesktopType( | |
| 604 popup_browser->host_desktop_type())); | |
| 605 } | 600 } |
| 606 | 601 |
| 607 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, | 602 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, |
| 608 ui::KeyboardCode key_code, | 603 ui::KeyboardCode key_code, |
| 609 int native_key_code, | 604 int native_key_code, |
| 610 int modifiers, | 605 int modifiers, |
| 611 NativeWebKeyboardEvent* event) { | 606 NativeWebKeyboardEvent* event) { |
| 612 event->nativeKeyCode = native_key_code; | 607 event->nativeKeyCode = native_key_code; |
| 613 event->windowsKeyCode = key_code; | 608 event->windowsKeyCode = key_code; |
| 614 event->setKeyIdentifierFromWindowsKeyCode(); | 609 event->setKeyIdentifierFromWindowsKeyCode(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 wait_for_new_tab.Wait(); | 708 wait_for_new_tab.Wait(); |
| 714 | 709 |
| 715 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), | 710 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), |
| 716 browser()->host_desktop_type())); | 711 browser()->host_desktop_type())); |
| 717 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 712 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 718 // Check that we create the background tab. | 713 // Check that we create the background tab. |
| 719 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 714 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 720 } | 715 } |
| 721 | 716 |
| 722 } // namespace | 717 } // namespace |
| OLD | NEW |