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

Side by Side Diff: chrome/browser/chromeos/login/merge_session_load_page_unittest.cc

Issue 23678007: OAuth2LoginManager+MergeSessionThrottle hardening, multi-profle support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "base/time/time.h"
6 #include "chrome/browser/chromeos/login/merge_session_load_page.h" 7 #include "chrome/browser/chromeos/login/merge_session_load_page.h"
8 #include "chrome/browser/chromeos/login/oauth2_login_manager.h"
9 #include "chrome/browser/chromeos/login/oauth2_login_manager_factory.h"
7 #include "chrome/browser/chromeos/login/user_manager.h" 10 #include "chrome/browser/chromeos/login/user_manager.h"
8 #include "chrome/browser/chromeos/settings/cros_settings.h" 11 #include "chrome/browser/chromeos/settings/cros_settings.h"
9 #include "chrome/browser/chromeos/settings/device_settings_service.h" 12 #include "chrome/browser/chromeos/settings/device_settings_service.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "content/public/browser/interstitial_page.h" 14 #include "content/public/browser/interstitial_page.h"
12 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/web_contents_tester.h" 17 #include "content/public/test/web_contents_tester.h"
15 18
16 using content::InterstitialPage; 19 using content::InterstitialPage;
17 using content::WebContents; 20 using content::WebContents;
18 using content::WebContentsTester; 21 using content::WebContentsTester;
19 22
20 namespace { 23 namespace {
21 24
22 const char kURL1[] = "http://www.google.com/"; 25 const char kURL1[] = "http://www.google.com/";
23 const char kURL2[] = "http://mail.google.com/"; 26 const char kURL2[] = "http://mail.google.com/";
24 27
28 const int64 kSessionMergeTimeout = 60;
29
25 } // namespace 30 } // namespace
26 31
27 namespace chromeos { 32 namespace chromeos {
28 33
29 class MergeSessionLoadPageTest; 34 class MergeSessionLoadPageTest;
30 35
31 // An MergeSessionLoadPage class that does not create windows. 36 // An MergeSessionLoadPage class that does not create windows.
32 class TestMergeSessionLoadPage : public MergeSessionLoadPage { 37 class TestMergeSessionLoadPage : public MergeSessionLoadPage {
33 public: 38 public:
34 TestMergeSessionLoadPage(WebContents* web_contents, 39 TestMergeSessionLoadPage(WebContents* web_contents,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void ShowInterstitial(const char* url) { 77 void ShowInterstitial(const char* url) {
73 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show(); 78 (new TestMergeSessionLoadPage(web_contents(), GURL(url), this))->Show();
74 } 79 }
75 80
76 // Returns the MergeSessionLoadPage currently showing or NULL if none is 81 // Returns the MergeSessionLoadPage currently showing or NULL if none is
77 // showing. 82 // showing.
78 InterstitialPage* GetMergeSessionLoadPage() { 83 InterstitialPage* GetMergeSessionLoadPage() {
79 return InterstitialPage::GetInterstitialPage(web_contents()); 84 return InterstitialPage::GetInterstitialPage(web_contents());
80 } 85 }
81 86
87 OAuth2LoginManager* GetOAuth2LoginManager() {
88 content::BrowserContext* browser_context =
89 web_contents()->GetBrowserContext();
90 if (!browser_context)
91 return NULL;
92
93 Profile* profile = Profile::FromBrowserContext(browser_context);
94 if (!profile)
95 return NULL;
96
97 OAuth2LoginManager* login_manager =
98 OAuth2LoginManagerFactory::GetInstance()->GetForProfile(
99 profile);
100 return login_manager;
101 }
102
103 void SetMergeSessionState(OAuth2LoginManager::SessionRestoreState state) {
104 OAuth2LoginManager* login_manager = GetOAuth2LoginManager();
105 ASSERT_TRUE(login_manager);
106 login_manager->SetSessionRestoreState(state);
107 }
108
109 void SetSessionRestoreStart(const base::Time& time) {
110 OAuth2LoginManager* login_manager = GetOAuth2LoginManager();
111 ASSERT_TRUE(login_manager);
112 login_manager->SetSessionRestoreStartForTesting(time);
113 }
114
82 private: 115 private:
83 ScopedTestDeviceSettingsService test_device_settings_service_; 116 ScopedTestDeviceSettingsService test_device_settings_service_;
84 ScopedTestCrosSettings test_cros_settings_; 117 ScopedTestCrosSettings test_cros_settings_;
85 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; 118 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
86 }; 119 };
87 120
88 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) { 121 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShown) {
89 UserManager::Get()->SetMergeSessionState( 122 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE);
90 UserManager::MERGE_STATUS_DONE);
91 // Start a load. 123 // Start a load.
92 Navigate(kURL1, 1); 124 Navigate(kURL1, 1);
93 // Load next page. 125 // Load next page.
126 controller().LoadURL(GURL(kURL2), content::Referrer(),
127 content::PAGE_TRANSITION_TYPED, std::string());
128
129 // Simulate the load causing an merge session interstitial page
130 // to be shown.
131 InterstitialPage* interstitial = GetMergeSessionLoadPage();
132 EXPECT_FALSE(interstitial);
133 }
134
135 TEST_F(MergeSessionLoadPageTest, MergeSessionPageNotShownOnTimeout) {
136 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS);
137 SetSessionRestoreStart(
138 base::Time::Now() +
139 base::TimeDelta::FromSeconds(kSessionMergeTimeout + 1));
140
141 // Start a load.
142 Navigate(kURL1, 1);
143 // Load next page.
94 controller().LoadURL(GURL(kURL2), content::Referrer(), 144 controller().LoadURL(GURL(kURL2), content::Referrer(),
95 content::PAGE_TRANSITION_TYPED, std::string()); 145 content::PAGE_TRANSITION_TYPED, std::string());
96 146
97 // Simulate the load causing an merge session interstitial page 147 // Simulate the load causing an merge session interstitial page
98 // to be shown. 148 // to be shown.
99 InterstitialPage* interstitial = GetMergeSessionLoadPage(); 149 InterstitialPage* interstitial = GetMergeSessionLoadPage();
100 EXPECT_FALSE(interstitial); 150 EXPECT_FALSE(interstitial);
101 } 151 }
102 152
103 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) { 153 TEST_F(MergeSessionLoadPageTest, MergeSessionPageShown) {
104 UserManager::Get()->SetMergeSessionState( 154 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS);
105 UserManager::MERGE_STATUS_IN_PROCESS); 155
106 // Start a load. 156 // Start a load.
107 Navigate(kURL1, 1); 157 Navigate(kURL1, 1);
108 // Load next page. 158 // Load next page.
109 controller().LoadURL(GURL(kURL2), content::Referrer(), 159 controller().LoadURL(GURL(kURL2), content::Referrer(),
110 content::PAGE_TRANSITION_TYPED, std::string()); 160 content::PAGE_TRANSITION_TYPED, std::string());
111 161
112 // Simulate the load causing an merge session interstitial page 162 // Simulate the load causing an merge session interstitial page
113 // to be shown. 163 // to be shown.
114 ShowInterstitial(kURL2); 164 ShowInterstitial(kURL2);
115 InterstitialPage* interstitial = GetMergeSessionLoadPage(); 165 InterstitialPage* interstitial = GetMergeSessionLoadPage();
116 ASSERT_TRUE(interstitial); 166 ASSERT_TRUE(interstitial);
117 base::RunLoop().RunUntilIdle(); 167 base::RunLoop().RunUntilIdle();
118 168
119 // Simulate merge session completion. 169 // Simulate merge session completion.
120 UserManager::Get()->SetMergeSessionState( 170 SetMergeSessionState(OAuth2LoginManager::SESSION_RESTORE_DONE);
121 UserManager::MERGE_STATUS_DONE);
122 base::RunLoop().RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
123 172
124 // The URL remains to be URL2. 173 // The URL remains to be URL2.
125 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec()); 174 EXPECT_EQ(kURL2, web_contents()->GetVisibleURL().spec());
126 175
127 // Commit navigation and the interstitial page is gone. 176 // Commit navigation and the interstitial page is gone.
128 Navigate(kURL2, 2); 177 Navigate(kURL2, 2);
129 EXPECT_FALSE(GetMergeSessionLoadPage()); 178 EXPECT_FALSE(GetMergeSessionLoadPage());
130 } 179 }
131 180
132 } // namespace chromeos 181 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/merge_session_load_page.cc ('k') | chrome/browser/chromeos/login/merge_session_throttle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698