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

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/navigation_controller.h" 19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h" 20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/render_view_test.h" 24 #include "content/public/test/render_view_test.h"
24 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
25 #include "content/public/test/web_contents_tester.h" 26 #include "content/public/test/web_contents_tester.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
28 29
29 typedef TabRestoreService::Tab Tab; 30 typedef TabRestoreService::Tab Tab;
30 typedef TabRestoreService::Window Window; 31 typedef TabRestoreService::Window Window;
31 using content::WebContentsTester; 32 using content::WebContentsTester;
32 33
(...skipping 14 matching lines...) Expand all
47 private: 48 private:
48 base::Time time_; 49 base::Time time_;
49 }; 50 };
50 51
51 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { 52 class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness {
52 public: 53 public:
53 TabRestoreServiceTest() { 54 TabRestoreServiceTest() {
54 url1_ = GURL("http://1"); 55 url1_ = GURL("http://1");
55 url2_ = GURL("http://2"); 56 url2_ = GURL("http://2");
56 url3_ = GURL("http://3"); 57 url3_ = GURL("http://3");
58 user_agent_override_ = "user_agent_override";
57 } 59 }
58 60
59 ~TabRestoreServiceTest() { 61 ~TabRestoreServiceTest() {
60 } 62 }
61 63
62 protected: 64 protected:
63 // testing::Test overrides 65 // testing::Test overrides
64 virtual void SetUp() { 66 virtual void SetUp() {
65 WebKit::initialize(webkit_platform_support_.Get()); 67 WebKit::initialize(webkit_platform_support_.Get());
66 ChromeRenderViewHostTestHarness::SetUp(); 68 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 131
130 AddWindowWithOneTabToSessionService(pinned); 132 AddWindowWithOneTabToSessionService(pinned);
131 133
132 // Set this, otherwise previous session won't be loaded. 134 // Set this, otherwise previous session won't be loaded.
133 profile()->set_last_session_exited_cleanly(false); 135 profile()->set_last_session_exited_cleanly(false);
134 } 136 }
135 137
136 GURL url1_; 138 GURL url1_;
137 GURL url2_; 139 GURL url2_;
138 GURL url3_; 140 GURL url3_;
141 std::string user_agent_override_;
139 scoped_ptr<TabRestoreService> service_; 142 scoped_ptr<TabRestoreService> service_;
140 TabRestoreTimeFactory* time_factory_; 143 TabRestoreTimeFactory* time_factory_;
141 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox 144 content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox
142 webkit_platform_support_; 145 webkit_platform_support_;
143 }; 146 };
144 147
145 TEST_F(TabRestoreServiceTest, Basic) { 148 TEST_F(TabRestoreServiceTest, Basic) {
146 AddThreeNavigations(); 149 AddThreeNavigations();
147 150
148 // Have the service record the tab. 151 // Have the service record the tab.
149 service_->CreateHistoricalTab(&controller(), -1); 152 service_->CreateHistoricalTab(&controller(), -1);
150 153
151 // Make sure an entry was created. 154 // Make sure an entry was created.
152 ASSERT_EQ(1U, service_->entries().size()); 155 ASSERT_EQ(1U, service_->entries().size());
153 156
154 // Make sure the entry matches. 157 // Make sure the entry matches.
155 TabRestoreService::Entry* entry = service_->entries().front(); 158 TabRestoreService::Entry* entry = service_->entries().front();
156 ASSERT_EQ(TabRestoreService::TAB, entry->type); 159 ASSERT_EQ(TabRestoreService::TAB, entry->type);
157 Tab* tab = static_cast<Tab*>(entry); 160 Tab* tab = static_cast<Tab*>(entry);
158 EXPECT_FALSE(tab->pinned); 161 EXPECT_FALSE(tab->pinned);
159 EXPECT_TRUE(tab->extension_app_id.empty()); 162 EXPECT_TRUE(tab->extension_app_id.empty());
160 ASSERT_EQ(3U, tab->navigations.size()); 163 ASSERT_EQ(3U, tab->navigations.size());
161 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 164 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
162 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 165 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
163 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 166 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
167 EXPECT_TRUE("" == tab->user_agent_override);
sky 2012/08/14 00:05:46 EXPECT_EQ
gone 2012/08/14 01:03:22 Done.
164 EXPECT_EQ(2, tab->current_navigation_index); 168 EXPECT_EQ(2, tab->current_navigation_index);
165 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 169 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
166 tab->timestamp.ToInternalValue()); 170 tab->timestamp.ToInternalValue());
167 171
168 NavigateToIndex(1); 172 NavigateToIndex(1);
169 173
170 // And check again. 174 // And check again, but set the user agent override this time.
175 contents()->SetUserAgentOverride(user_agent_override_);
171 service_->CreateHistoricalTab(&controller(), -1); 176 service_->CreateHistoricalTab(&controller(), -1);
172 177
173 // There should be two entries now. 178 // There should be two entries now.
174 ASSERT_EQ(2U, service_->entries().size()); 179 ASSERT_EQ(2U, service_->entries().size());
175 180
176 // Make sure the entry matches 181 // Make sure the entry matches.
177 entry = service_->entries().front(); 182 entry = service_->entries().front();
178 ASSERT_EQ(TabRestoreService::TAB, entry->type); 183 ASSERT_EQ(TabRestoreService::TAB, entry->type);
179 tab = static_cast<Tab*>(entry); 184 tab = static_cast<Tab*>(entry);
180 EXPECT_FALSE(tab->pinned); 185 EXPECT_FALSE(tab->pinned);
181 ASSERT_EQ(3U, tab->navigations.size()); 186 ASSERT_EQ(3U, tab->navigations.size());
182 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); 187 EXPECT_EQ(url1_, tab->navigations[0].virtual_url());
183 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); 188 EXPECT_EQ(url2_, tab->navigations[1].virtual_url());
184 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); 189 EXPECT_EQ(url3_, tab->navigations[2].virtual_url());
190 EXPECT_TRUE(user_agent_override_ == tab->user_agent_override);
sky 2012/08/14 00:05:46 EXPECT_EQ
gone 2012/08/14 01:03:22 Done.
185 EXPECT_EQ(1, tab->current_navigation_index); 191 EXPECT_EQ(1, tab->current_navigation_index);
186 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 192 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
187 tab->timestamp.ToInternalValue()); 193 tab->timestamp.ToInternalValue());
188 } 194 }
189 195
190 // Make sure TabRestoreService doesn't create an entry for a tab with no 196 // Make sure TabRestoreService doesn't create an entry for a tab with no
191 // navigations. 197 // navigations.
192 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { 198 TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) {
193 service_->CreateHistoricalTab(&controller(), -1); 199 service_->CreateHistoricalTab(&controller(), -1);
194 EXPECT_TRUE(service_->entries().empty()); 200 EXPECT_TRUE(service_->entries().empty());
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 for (size_t i = 0; i < max_entries + 5; i++) { 647 for (size_t i = 0; i < max_entries + 5; i++) {
642 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); 648 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i))));
643 service_->CreateHistoricalTab(&controller(), -1); 649 service_->CreateHistoricalTab(&controller(), -1);
644 } 650 }
645 651
646 EXPECT_EQ(max_entries, service_->entries_.size()); 652 EXPECT_EQ(max_entries, service_->entries_.size());
647 // This should not crash. 653 // This should not crash.
648 service_->LoadTabsFromLastSession(); 654 service_->LoadTabsFromLastSession();
649 EXPECT_EQ(max_entries, service_->entries_.size()); 655 EXPECT_EQ(max_entries, service_->entries_.size());
650 } 656 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698