OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { | |
839 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | |
840 instant()->OnAutocompleteGotFocus(); | |
841 WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); | |
842 | |
843 // Instant is not showing, so a refresh should create a new preview contents. | |
844 instant()->OnStaleLoader(); | |
845 WaitFor(chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); | |
846 // Can't compare the old and new loader pointers here since the same address | |
847 // may be resued when the new loader is created. | |
sreeram
2012/08/24 21:06:25
I just realized that we _can_ test something here
Shishir
2012/08/24 22:17:39
Done.
Although this works, it feels like we are u
| |
848 | |
849 // Show Instant. | |
850 SetOmniboxText("query"); | |
851 WaitFor(chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); | |
852 TabContents* preview_tab = instant()->GetPreviewContents(); | |
853 | |
854 // Refresh the loader, the preview contents should remain the same. | |
855 instant()->OnStaleLoader(); | |
856 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | |
sreeram
2012/08/24 21:06:25
Since we know the pointers can be reused, this isn
Shishir
2012/08/24 22:17:39
Done. Will have to stop timer here though.
| |
857 } | |
OLD | NEW |