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

Side by Side Diff: chrome/browser/sessions/tab_restore_service_browsertest.cc

Issue 10827168: Fix user agent override restore pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 8 years, 4 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
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 "base/stringprintf.h" 5 #include "base/stringprintf.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/sessions/session_service_factory.h" 7 #include "chrome/browser/sessions/session_service_factory.h"
8 #include "chrome/browser/sessions/session_service.h" 8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sessions/session_types.h" 9 #include "chrome/browser/sessions/session_types.h"
10 #include "chrome/browser/sessions/tab_restore_service.h" 10 #include "chrome/browser/sessions/tab_restore_service.h"
11 #include "chrome/browser/sessions/tab_restore_service_factory.h" 11 #include "chrome/browser/sessions/tab_restore_service_factory.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/chrome_render_view_test.h" 16 #include "chrome/test/base/chrome_render_view_test.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
21 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/render_view_test.h" 25 #include "content/public/test/render_view_test.h"
25 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "content/public/test/web_contents_tester.h" 28 #include "content/public/test/web_contents_tester.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
30 31
31 typedef TabRestoreService::Tab Tab; 32 typedef TabRestoreService::Tab Tab;
32 typedef TabRestoreService::Window Window; 33 typedef TabRestoreService::Window Window;
33 using content::WebContentsTester; 34 using content::WebContentsTester;
(...skipping 16 matching lines...) Expand all
50 base::Time time_; 51 base::Time time_;
51 }; 52 };
52 53
53 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { 54 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
54 public: 55 public:
55 TabRestoreServiceTest() 56 TabRestoreServiceTest()
56 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 57 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
57 url1_ = GURL("http://1"); 58 url1_ = GURL("http://1");
58 url2_ = GURL("http://2"); 59 url2_ = GURL("http://2");
59 url3_ = GURL("http://3"); 60 url3_ = GURL("http://3");
61 user_agent_override_ = "user_agent_override";
60 } 62 }
61 63
62 ~TabRestoreServiceTest() { 64 ~TabRestoreServiceTest() {
63 } 65 }
64 66
65 protected: 67 protected:
66 // testing::Test overrides 68 // testing::Test overrides
67 virtual void SetUp() { 69 virtual void SetUp() {
68 WebKit::initialize(webkit_platform_support_.Get()); 70 WebKit::initialize(webkit_platform_support_.Get());
69 ChromeRenderViewHostTestHarness::SetUp(); 71 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 134
133 AddWindowWithOneTabToSessionService(pinned); 135 AddWindowWithOneTabToSessionService(pinned);
134 136
135 // Set this, otherwise previous session won't be loaded. 137 // Set this, otherwise previous session won't be loaded.
136 profile()->set_last_session_exited_cleanly(false); 138 profile()->set_last_session_exited_cleanly(false);
137 } 139 }
138 140
139 GURL url1_; 141 GURL url1_;
140 GURL url2_; 142 GURL url2_;
141 GURL url3_; 143 GURL url3_;
144 std::string user_agent_override_;
142 scoped_ptr<TabRestoreService> service_; 145 scoped_ptr<TabRestoreService> service_;
143 TabRestoreTimeFactory* time_factory_; 146 TabRestoreTimeFactory* time_factory_;
144 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox 147 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox
145 webkit_platform_support_; 148 webkit_platform_support_;
146 content::TestBrowserThread ui_thread_; 149 content::TestBrowserThread ui_thread_;
147 }; 150 };
148 151
149 TEST_F(TabRestoreServiceTest, Basic) { 152 TEST_F(TabRestoreServiceTest, Basic) {
150 AddThreeNavigations(); 153 AddThreeNavigations();
151 154
152 // Have the service record the tab. 155 // Have the service record the tab.
153 service_->CreateHistoricalTab(contents(), -1); 156 service_->CreateHistoricalTab(contents(), -1);
154 157
155 // Make sure an entry was created. 158 // Make sure an entry was created.
156 ASSERT_EQ(1U, service_->entries().size()); 159 ASSERT_EQ(1U, service_->entries().size());
157 160
158 // Make sure the entry matches. 161 // Make sure the entry matches.
159 TabRestoreService::Entry* entry = service_->entries().front(); 162 TabRestoreService::Entry* entry = service_->entries().front();
160 ASSERT_EQ(TabRestoreService::TAB, entry->type); 163 ASSERT_EQ(TabRestoreService::TAB, entry->type);
161 Tab* tab = static_cast<Tab*>(entry); 164 Tab* tab = static_cast<Tab*>(entry);
162 EXPECT_FALSE(tab->pinned); 165 EXPECT_FALSE(tab->pinned);
163 EXPECT_TRUE(tab->extension_app_id.empty()); 166 EXPECT_TRUE(tab->extension_app_id.empty());
164 ASSERT_EQ(3U, tab->navigations.size()); 167 ASSERT_EQ(3U, tab->navigations.size());
165 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 168 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
166 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 169 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
167 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 170 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
171 EXPECT_EQ("", tab->user_agent_override);
168 EXPECT_EQ(2, tab->current_navigation_index); 172 EXPECT_EQ(2, tab->current_navigation_index);
169 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 173 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
170 tab->timestamp.ToInternalValue()); 174 tab->timestamp.ToInternalValue());
171 175
172 NavigateToIndex(1); 176 NavigateToIndex(1);
173 177
174 // And check again. 178 // And check again, but set the user agent override this time.
179 contents()->SetUserAgentOverride(user_agent_override_);
175 service_->CreateHistoricalTab(contents(), -1); 180 service_->CreateHistoricalTab(contents(), -1);
176 181
177 // There should be two entries now. 182 // There should be two entries now.
178 ASSERT_EQ(2U, service_->entries().size()); 183 ASSERT_EQ(2U, service_->entries().size());
179 184
180 // Make sure the entry matches 185 // Make sure the entry matches.
181 entry = service_->entries().front(); 186 entry = service_->entries().front();
182 ASSERT_EQ(TabRestoreService::TAB, entry->type); 187 ASSERT_EQ(TabRestoreService::TAB, entry->type);
183 tab = static_cast<Tab*>(entry); 188 tab = static_cast<Tab*>(entry);
184 EXPECT_FALSE(tab->pinned); 189 EXPECT_FALSE(tab->pinned);
185 ASSERT_EQ(3U, tab->navigations.size()); 190 ASSERT_EQ(3U, tab->navigations.size());
186 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); 191 EXPECT_EQ(url1_, tab->navigations[0].virtual_url());
187 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); 192 EXPECT_EQ(url2_, tab->navigations[1].virtual_url());
188 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); 193 EXPECT_EQ(url3_, tab->navigations[2].virtual_url());
194 EXPECT_EQ(user_agent_override_, tab->user_agent_override);
189 EXPECT_EQ(1, tab->current_navigation_index); 195 EXPECT_EQ(1, tab->current_navigation_index);
190 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 196 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
191 tab->timestamp.ToInternalValue()); 197 tab->timestamp.ToInternalValue());
192 } 198 }
193 199
194 // Make sure TabRestoreService doesn't create an entry for a tab with no 200 // Make sure TabRestoreService doesn't create an entry for a tab with no
195 // navigations. 201 // navigations.
196 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { 202 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) {
197 service_->CreateHistoricalTab(contents(), -1); 203 service_->CreateHistoricalTab(contents(), -1);
198 EXPECT_TRUE(service_->entries().empty()); 204 EXPECT_TRUE(service_->entries().empty());
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 for (size_t i = 0; i < max_entries + 5; i++) { 651 for (size_t i = 0; i < max_entries + 5; i++) {
646 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); 652 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i))));
647 service_->CreateHistoricalTab(contents(), -1); 653 service_->CreateHistoricalTab(contents(), -1);
648 } 654 }
649 655
650 EXPECT_EQ(max_entries, service_->entries_.size()); 656 EXPECT_EQ(max_entries, service_->entries_.size());
651 // This should not crash. 657 // This should not crash.
652 service_->LoadTabsFromLastSession(); 658 service_->LoadTabsFromLastSession();
653 EXPECT_EQ(max_entries, service_->entries_.size()); 659 EXPECT_EQ(max_entries, service_->entries_.size());
654 } 660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698