| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.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/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | 16 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" |
| 16 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" | 17 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" |
| 17 #include "chrome/browser/chromeos/login/signin_specifics.h" | 18 #include "chrome/browser/chromeos/login/signin_specifics.h" |
| 18 #include "chrome/browser/chromeos/login/startup_utils.h" | 19 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 19 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 20 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| 20 #include "chrome/browser/chromeos/login/wizard_controller.h" | 21 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 21 #include "chrome/browser/extensions/chrome_extension_test_notification_observer.
h" | 22 #include "chrome/browser/extensions/chrome_extension_test_notification_observer.
h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 27 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
| 26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 30 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 29 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "chromeos/login/auth/key.h" | 33 #include "chromeos/login/auth/key.h" |
| 32 #include "chromeos/login/auth/user_context.h" | 34 #include "chromeos/login/auth/user_context.h" |
| 33 #include "components/app_modal/javascript_app_modal_dialog.h" | |
| 34 #include "components/app_modal/native_app_modal_dialog.h" | |
| 35 #include "components/browser_sync/browser_sync_switches.h" | 35 #include "components/browser_sync/browser_sync_switches.h" |
| 36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 37 #include "components/signin/core/account_id/account_id.h" | 37 #include "components/signin/core/account_id/account_id.h" |
| 38 #include "components/signin/core/browser/account_tracker_service.h" | 38 #include "components/signin/core/browser/account_tracker_service.h" |
| 39 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 39 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 40 #include "components/user_manager/user.h" | 40 #include "components/user_manager/user.h" |
| 41 #include "components/user_manager/user_manager.h" | 41 #include "components/user_manager/user_manager.h" |
| 42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/test/browser_test_utils.h" | 44 #include "content/public/test/browser_test_utils.h" |
| 45 #include "extensions/browser/process_manager.h" | 45 #include "extensions/browser/process_manager.h" |
| 46 #include "extensions/test/extension_test_message_listener.h" | 46 #include "extensions/test/extension_test_message_listener.h" |
| 47 #include "extensions/test/result_catcher.h" | 47 #include "extensions/test/result_catcher.h" |
| 48 #include "google_apis/gaia/gaia_constants.h" | 48 #include "google_apis/gaia/gaia_constants.h" |
| 49 #include "google_apis/gaia/gaia_urls.h" | 49 #include "google_apis/gaia/gaia_urls.h" |
| 50 #include "net/cookies/canonical_cookie.h" | 50 #include "net/cookies/canonical_cookie.h" |
| 51 #include "net/cookies/cookie_store.h" | 51 #include "net/cookies/cookie_store.h" |
| 52 #include "net/test/embedded_test_server/http_request.h" | 52 #include "net/test/embedded_test_server/http_request.h" |
| 53 #include "net/test/embedded_test_server/http_response.h" | 53 #include "net/test/embedded_test_server/http_response.h" |
| 54 #include "net/url_request/url_request_context.h" | 54 #include "net/url_request/url_request_context.h" |
| 55 #include "net/url_request/url_request_context_getter.h" | 55 #include "net/url_request/url_request_context_getter.h" |
| 56 | 56 |
| 57 using app_modal::AppModalDialog; | |
| 58 using app_modal::JavaScriptAppModalDialog; | |
| 59 using net::test_server::BasicHttpResponse; | 57 using net::test_server::BasicHttpResponse; |
| 60 using net::test_server::HttpRequest; | 58 using net::test_server::HttpRequest; |
| 61 using net::test_server::HttpResponse; | 59 using net::test_server::HttpResponse; |
| 62 | 60 |
| 63 namespace chromeos { | 61 namespace chromeos { |
| 64 | 62 |
| 65 namespace { | 63 namespace { |
| 66 | 64 |
| 67 // Email of owner account for test. | 65 // Email of owner account for test. |
| 68 const char kTestGaiaId[] = "12345"; | 66 const char kTestGaiaId[] = "12345"; |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 Browser* browser = displayer.browser(); | 793 Browser* browser = displayer.browser(); |
| 796 if (browser->tab_strip_model()->count() == 0) | 794 if (browser->tab_strip_model()->count() == 0) |
| 797 chrome::AddTabAt(browser, GURL(), -1, true); | 795 chrome::AddTabAt(browser, GURL(), -1, true); |
| 798 return browser; | 796 return browser; |
| 799 } | 797 } |
| 800 | 798 |
| 801 IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { | 799 IN_PROC_BROWSER_TEST_F(MergeSessionTest, PageThrottle) { |
| 802 StartNewUserSession(false); | 800 StartNewUserSession(false); |
| 803 | 801 |
| 804 // Try to open a page from google.com. | 802 // Try to open a page from google.com. |
| 805 Browser* browser = | 803 Browser* browser = FindOrCreateVisibleBrowser(profile()); |
| 806 FindOrCreateVisibleBrowser(profile()); | |
| 807 ui_test_utils::NavigateToURLWithDisposition( | 804 ui_test_utils::NavigateToURLWithDisposition( |
| 808 browser, fake_google_page_url_, WindowOpenDisposition::CURRENT_TAB, | 805 browser, fake_google_page_url_, WindowOpenDisposition::CURRENT_TAB, |
| 809 ui_test_utils::BROWSER_TEST_NONE); | 806 ui_test_utils::BROWSER_TEST_NONE); |
| 810 | 807 |
| 808 // JavaScript dialog wait setup. |
| 809 content::WebContents* tab = |
| 810 browser->tab_strip_model()->GetActiveWebContents(); |
| 811 JavaScriptDialogTabHelper* js_helper = |
| 812 JavaScriptDialogTabHelper::FromWebContents(tab); |
| 813 base::RunLoop dialog_wait; |
| 814 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure()); |
| 815 |
| 811 // Wait until we get send merge session request. | 816 // Wait until we get send merge session request. |
| 812 WaitForMergeSessionToStart(); | 817 WaitForMergeSessionToStart(); |
| 813 | 818 |
| 814 // Make sure the page is blocked by the throttle. | 819 // Make sure the page is blocked by the throttle. |
| 815 EXPECT_FALSE(fake_google_.IsPageRequested()); | 820 EXPECT_FALSE(fake_google_.IsPageRequested()); |
| 816 | 821 |
| 817 // Check that throttle page is displayed instead. | 822 // Check that throttle page is displayed instead. |
| 818 base::string16 title; | 823 base::string16 title; |
| 819 ui_test_utils::GetCurrentTabTitle(browser, &title); | 824 ui_test_utils::GetCurrentTabTitle(browser, &title); |
| 820 DVLOG(1) << "Loaded page at the start : " << title; | 825 DVLOG(1) << "Loaded page at the start : " << title; |
| 821 | 826 |
| 822 // Unblock GAIA request. | 827 // Unblock GAIA request. |
| 823 UnblockMergeSession(); | 828 UnblockMergeSession(); |
| 824 | 829 |
| 825 // Wait for the session merge to finish. | 830 // Wait for the session merge to finish. |
| 826 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); | 831 WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); |
| 827 | 832 |
| 828 // Make sure the test page is served. | 833 // Make sure the test page is served. |
| 829 fake_google_.WaitForPageRequest(); | 834 fake_google_.WaitForPageRequest(); |
| 830 | 835 |
| 831 // Check that real page is no longer blocked by the throttle and that the | 836 // Check that real page is no longer blocked by the throttle and that the |
| 832 // real page pops up JS dialog. | 837 // real page pops up JS dialog. |
| 833 AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog(); | 838 dialog_wait.Run(); |
| 834 ASSERT_TRUE(dialog->IsJavaScriptModalDialog()); | 839 js_helper->HandleJavaScriptDialog(tab, true, nullptr); |
| 835 JavaScriptAppModalDialog* js_dialog = | |
| 836 static_cast<JavaScriptAppModalDialog*>(dialog); | |
| 837 js_dialog->native_dialog()->AcceptAppModalDialog(); | |
| 838 | 840 |
| 839 ui_test_utils::GetCurrentTabTitle(browser, &title); | 841 ui_test_utils::GetCurrentTabTitle(browser, &title); |
| 840 DVLOG(1) << "Loaded page at the end : " << title; | 842 DVLOG(1) << "Loaded page at the end : " << title; |
| 841 } | 843 } |
| 842 | 844 |
| 843 IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) { | 845 IN_PROC_BROWSER_TEST_F(MergeSessionTest, XHRThrottle) { |
| 844 StartNewUserSession(false); | 846 StartNewUserSession(false); |
| 845 | 847 |
| 846 // Wait until we get send merge session request. | 848 // Wait until we get send merge session request. |
| 847 WaitForMergeSessionToStart(); | 849 WaitForMergeSessionToStart(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 | 891 |
| 890 if (!catcher.GetNextResult()) { | 892 if (!catcher.GetNextResult()) { |
| 891 std::string message = catcher.message(); | 893 std::string message = catcher.message(); |
| 892 ADD_FAILURE() << "Tests failed: " << message; | 894 ADD_FAILURE() << "Tests failed: " << message; |
| 893 } | 895 } |
| 894 | 896 |
| 895 EXPECT_TRUE(fake_google_.IsPageRequested()); | 897 EXPECT_TRUE(fake_google_.IsPageRequested()); |
| 896 } | 898 } |
| 897 | 899 |
| 898 } // namespace chromeos | 900 } // namespace chromeos |
| OLD | NEW |