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

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: Nit addressing 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_ = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
62 " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
60 } 63 }
61 64
62 ~TabRestoreServiceTest() { 65 ~TabRestoreServiceTest() {
63 } 66 }
64 67
65 protected: 68 protected:
66 // testing::Test overrides 69 // testing::Test overrides
67 virtual void SetUp() { 70 virtual void SetUp() {
68 WebKit::initialize(webkit_platform_support_.Get()); 71 WebKit::initialize(webkit_platform_support_.Get());
69 ChromeRenderViewHostTestHarness::SetUp(); 72 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 135
133 AddWindowWithOneTabToSessionService(pinned); 136 AddWindowWithOneTabToSessionService(pinned);
134 137
135 // Set this, otherwise previous session won't be loaded. 138 // Set this, otherwise previous session won't be loaded.
136 profile()->set_last_session_exited_cleanly(false); 139 profile()->set_last_session_exited_cleanly(false);
137 } 140 }
138 141
139 GURL url1_; 142 GURL url1_;
140 GURL url2_; 143 GURL url2_;
141 GURL url3_; 144 GURL url3_;
145 std::string user_agent_override_;
142 scoped_ptr<TabRestoreService> service_; 146 scoped_ptr<TabRestoreService> service_;
143 TabRestoreTimeFactory* time_factory_; 147 TabRestoreTimeFactory* time_factory_;
144 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox 148 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox
145 webkit_platform_support_; 149 webkit_platform_support_;
146 content::TestBrowserThread ui_thread_; 150 content::TestBrowserThread ui_thread_;
147 }; 151 };
148 152
149 TEST_F(TabRestoreServiceTest, Basic) { 153 TEST_F(TabRestoreServiceTest, Basic) {
150 AddThreeNavigations(); 154 AddThreeNavigations();
151 155
152 // Have the service record the tab. 156 // Have the service record the tab.
153 service_->CreateHistoricalTab(contents(), -1); 157 service_->CreateHistoricalTab(contents(), -1);
154 158
155 // Make sure an entry was created. 159 // Make sure an entry was created.
156 ASSERT_EQ(1U, service_->entries().size()); 160 ASSERT_EQ(1U, service_->entries().size());
157 161
158 // Make sure the entry matches. 162 // Make sure the entry matches.
159 TabRestoreService::Entry* entry = service_->entries().front(); 163 TabRestoreService::Entry* entry = service_->entries().front();
160 ASSERT_EQ(TabRestoreService::TAB, entry->type); 164 ASSERT_EQ(TabRestoreService::TAB, entry->type);
161 Tab* tab = static_cast<Tab*>(entry); 165 Tab* tab = static_cast<Tab*>(entry);
162 EXPECT_FALSE(tab->pinned); 166 EXPECT_FALSE(tab->pinned);
163 EXPECT_TRUE(tab->extension_app_id.empty()); 167 EXPECT_TRUE(tab->extension_app_id.empty());
164 ASSERT_EQ(3U, tab->navigations.size()); 168 ASSERT_EQ(3U, tab->navigations.size());
165 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 169 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
166 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 170 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
167 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 171 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
172 EXPECT_EQ("", tab->user_agent_override);
168 EXPECT_EQ(2, tab->current_navigation_index); 173 EXPECT_EQ(2, tab->current_navigation_index);
169 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 174 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
170 tab->timestamp.ToInternalValue()); 175 tab->timestamp.ToInternalValue());
171 176
172 NavigateToIndex(1); 177 NavigateToIndex(1);
173 178
174 // And check again. 179 // And check again, but set the user agent override this time.
180 contents()->SetUserAgentOverride(user_agent_override_);
175 service_->CreateHistoricalTab(contents(), -1); 181 service_->CreateHistoricalTab(contents(), -1);
176 182
177 // There should be two entries now. 183 // There should be two entries now.
178 ASSERT_EQ(2U, service_->entries().size()); 184 ASSERT_EQ(2U, service_->entries().size());
179 185
180 // Make sure the entry matches 186 // Make sure the entry matches.
181 entry = service_->entries().front(); 187 entry = service_->entries().front();
182 ASSERT_EQ(TabRestoreService::TAB, entry->type); 188 ASSERT_EQ(TabRestoreService::TAB, entry->type);
183 tab = static_cast<Tab*>(entry); 189 tab = static_cast<Tab*>(entry);
184 EXPECT_FALSE(tab->pinned); 190 EXPECT_FALSE(tab->pinned);
185 ASSERT_EQ(3U, tab->navigations.size()); 191 ASSERT_EQ(3U, tab->navigations.size());
186 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); 192 EXPECT_EQ(url1_, tab->navigations[0].virtual_url());
187 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); 193 EXPECT_EQ(url2_, tab->navigations[1].virtual_url());
188 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); 194 EXPECT_EQ(url3_, tab->navigations[2].virtual_url());
195 EXPECT_EQ(user_agent_override_, tab->user_agent_override);
189 EXPECT_EQ(1, tab->current_navigation_index); 196 EXPECT_EQ(1, tab->current_navigation_index);
190 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 197 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
191 tab->timestamp.ToInternalValue()); 198 tab->timestamp.ToInternalValue());
192 } 199 }
193 200
194 // Make sure TabRestoreService doesn't create an entry for a tab with no 201 // Make sure TabRestoreService doesn't create an entry for a tab with no
195 // navigations. 202 // navigations.
196 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { 203 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) {
197 service_->CreateHistoricalTab(contents(), -1); 204 service_->CreateHistoricalTab(contents(), -1);
198 EXPECT_TRUE(service_->entries().empty()); 205 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++) { 652 for (size_t i = 0; i < max_entries + 5; i++) {
646 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); 653 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i))));
647 service_->CreateHistoricalTab(contents(), -1); 654 service_->CreateHistoricalTab(contents(), -1);
648 } 655 }
649 656
650 EXPECT_EQ(max_entries, service_->entries_.size()); 657 EXPECT_EQ(max_entries, service_->entries_.size());
651 // This should not crash. 658 // This should not crash.
652 service_->LoadTabsFromLastSession(); 659 service_->LoadTabsFromLastSession();
653 EXPECT_EQ(max_entries, service_->entries_.size()); 660 EXPECT_EQ(max_entries, service_->entries_.size());
654 } 661 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698