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

Side by Side Diff: chrome/browser/instant/instant_browsertest.cc

Issue 10829436: Recreate the loader as soon as it is deleted and ensure that it does not become stale. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Spelling fix. Created 8 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
« no previous file with comments | « no previous file | chrome/browser/instant/instant_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "chrome/browser/content_settings/host_content_settings_map.h" 7 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/history/history.h" 8 #include "chrome/browser/history/history.h"
9 #include "chrome/browser/history/history_service_factory.h" 9 #include "chrome/browser/history/history_service_factory.h"
10 #include "chrome/browser/instant/instant_controller.h" 10 #include "chrome/browser/instant/instant_controller.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Before the commit, the active tab is the NTP (i.e., not Instant). 230 // Before the commit, the active tab is the NTP (i.e., not Instant).
231 TabContents* active_tab = chrome::GetActiveTabContents(browser()); 231 TabContents* active_tab = chrome::GetActiveTabContents(browser());
232 EXPECT_NE(preview_tab, active_tab); 232 EXPECT_NE(preview_tab, active_tab);
233 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); 233 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount());
234 EXPECT_EQ(std::string(chrome::kAboutBlankURL), 234 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
235 omnibox()->model()->PermanentURL().spec()); 235 omnibox()->model()->PermanentURL().spec());
236 236
237 // Commit the search by pressing Enter. 237 // Commit the search by pressing Enter.
238 browser()->window()->GetLocationBar()->AcceptInput(); 238 browser()->window()->GetLocationBar()->AcceptInput();
239 239
240 // After the commit, Instant should not be showing, or even have a preview. 240 // After the commit, Instant should not be showing.
241 EXPECT_FALSE(instant()->GetPreviewContents());
242 EXPECT_FALSE(instant()->IsCurrent()); 241 EXPECT_FALSE(instant()->IsCurrent());
243 EXPECT_FALSE(instant()->is_showing()); 242 EXPECT_FALSE(instant()->is_showing());
244 243
244 // The old loader is deleted and a new one is created.
245 EXPECT_TRUE(instant()->GetPreviewContents());
246 EXPECT_NE(instant()->GetPreviewContents(), preview_tab);
247
245 // Check that the current active tab is indeed what was once the preview. 248 // Check that the current active tab is indeed what was once the preview.
246 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); 249 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser()));
247 250
248 // We should have two navigation entries, one for the NTP, and one for the 251 // We should have two navigation entries, one for the NTP, and one for the
249 // Instant search that was committed. 252 // Instant search that was committed.
250 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); 253 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount());
251 254
252 // Check that the omnibox contains the Instant URL we loaded. 255 // Check that the omnibox contains the Instant URL we loaded.
253 std::string instant_url = TemplateURLServiceFactory::GetForProfile( 256 std::string instant_url = TemplateURLServiceFactory::GetForProfile(
254 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). 257 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref().
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 TabContents* active_tab = chrome::GetActiveTabContents(browser()); 291 TabContents* active_tab = chrome::GetActiveTabContents(browser());
289 EXPECT_NE(preview_tab, active_tab); 292 EXPECT_NE(preview_tab, active_tab);
290 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); 293 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount());
291 EXPECT_EQ(std::string(chrome::kAboutBlankURL), 294 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
292 omnibox()->model()->PermanentURL().spec()); 295 omnibox()->model()->PermanentURL().spec());
293 296
294 // Commit the search by clicking on the preview. 297 // Commit the search by clicking on the preview.
295 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 298 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
296 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 299 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
297 300
298 // After the commit, Instant should not be showing, or even have a preview. 301 // After the commit, Instant should not be showing.
299 EXPECT_FALSE(instant()->GetPreviewContents());
300 EXPECT_FALSE(instant()->IsCurrent()); 302 EXPECT_FALSE(instant()->IsCurrent());
301 EXPECT_FALSE(instant()->is_showing()); 303 EXPECT_FALSE(instant()->is_showing());
302 304
305 // The old loader is deleted and a new one is created.
306 EXPECT_TRUE(instant()->GetPreviewContents());
307 EXPECT_NE(instant()->GetPreviewContents(), preview_tab);
308
303 // Check that the current active tab is indeed what was once the preview. 309 // Check that the current active tab is indeed what was once the preview.
304 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); 310 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser()));
305 311
306 // We should have two navigation entries, one for the NTP, and one for the 312 // We should have two navigation entries, one for the NTP, and one for the
307 // Instant search that was committed. 313 // Instant search that was committed.
308 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); 314 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount());
309 315
310 // Check that the omnibox contains the Instant URL we loaded. 316 // Check that the omnibox contains the Instant URL we loaded.
311 std::string instant_url = TemplateURLServiceFactory::GetForProfile( 317 std::string instant_url = TemplateURLServiceFactory::GetForProfile(
312 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). 318 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref().
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 content::WindowedNotificationObserver observer( 824 content::WindowedNotificationObserver observer(
819 chrome::NOTIFICATION_INSTANT_CONTROLLER_HIDDEN, 825 chrome::NOTIFICATION_INSTANT_CONTROLLER_HIDDEN,
820 content::NotificationService::AllSources()); 826 content::NotificationService::AllSources());
821 chrome::NewEmptyWindow(browser()->profile()); 827 chrome::NewEmptyWindow(browser()->profile());
822 observer.Wait(); 828 observer.Wait();
823 EXPECT_TRUE(instant()->GetPreviewContents()); 829 EXPECT_TRUE(instant()->GetPreviewContents());
824 EXPECT_FALSE(instant()->IsCurrent()); 830 EXPECT_FALSE(instant()->IsCurrent());
825 EXPECT_FALSE(instant()->is_showing()); 831 EXPECT_FALSE(instant()->is_showing());
826 } 832 }
827 #endif 833 #endif
834
835 // Tests that:
836 // - Instant loader is recreated on OnStaleLoader call when it is hidden.
837 // - Instant loader is not recreated on OnStaleLoader call when it is visible.
838 // - Instant loader will be recreated when omnibox loses focus after the timer
839 // has stopped.
840 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) {
841 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html"));
842 instant()->OnAutocompleteGotFocus();
843 WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED);
844
845 // Instant is not showing, so a refresh should create a new preview contents.
846 EXPECT_TRUE(instant()->loader()->supports_instant());
847 instant()->OnStaleLoader();
848 EXPECT_FALSE(instant()->loader()->supports_instant());
849 WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED);
850
851 // Show Instant.
852 SetOmniboxText("query");
853 WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN);
854
855 // Refresh the loader, the preview contents should remain the same.
856 instant()->OnStaleLoader();
857 EXPECT_TRUE(instant()->is_showing());
858
859 instant()->stale_loader_timer_.Stop();
860 // The refresh should happen once the omnibox loses focus.
861 EXPECT_TRUE(instant()->loader()->supports_instant());
862 instant()->OnAutocompleteLostFocus(NULL);
863 EXPECT_FALSE(instant()->loader()->supports_instant());
864 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/instant/instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698