OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/search/instant_tab.h" | 5 #include "chrome/browser/ui/search/instant_tab.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void InstantTabTest::SetUp() { | 68 void InstantTabTest::SetUp() { |
69 ChromeRenderViewHostTestHarness::SetUp(); | 69 ChromeRenderViewHostTestHarness::SetUp(); |
70 SearchTabHelper::CreateForWebContents(web_contents()); | 70 SearchTabHelper::CreateForWebContents(web_contents()); |
71 auto factory = base::MakeUnique<MockSearchBoxClientFactory>(); | 71 auto factory = base::MakeUnique<MockSearchBoxClientFactory>(); |
72 ON_CALL(*factory, GetSearchBox()).WillByDefault(Return(&mock_search_box)); | 72 ON_CALL(*factory, GetSearchBox()).WillByDefault(Return(&mock_search_box)); |
73 search_tab() | 73 search_tab() |
74 ->ipc_router_for_testing() | 74 ->ipc_router_for_testing() |
75 .set_search_box_client_factory_for_testing(std::move(factory)); | 75 .set_search_box_client_factory_for_testing(std::move(factory)); |
76 } | 76 } |
77 | 77 |
78 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) { | |
79 page.reset(new InstantTab(&delegate, web_contents())); | |
80 EXPECT_FALSE(SupportsInstant()); | |
81 page->Init(); | |
82 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | |
83 search_tab()->DetermineIfPageSupportsInstant(); | |
84 EXPECT_TRUE(SupportsInstant()); | |
85 } | |
86 | |
87 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { | |
88 page.reset(new InstantTab(&delegate, web_contents())); | |
89 EXPECT_FALSE(SupportsInstant()); | |
90 page->Init(); | |
91 NavigateAndCommit(GURL("chrome-search://foo/bar")); | |
92 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); | |
93 search_tab()->DetermineIfPageSupportsInstant(); | |
94 } | |
95 | |
96 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { | 78 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { |
97 page.reset(new InstantTab(&delegate, web_contents())); | 79 page.reset(new InstantTab(&delegate, web_contents())); |
98 EXPECT_FALSE(SupportsInstant()); | 80 EXPECT_FALSE(SupportsInstant()); |
99 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 81 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
100 page->Init(); | 82 page->Init(); |
101 | 83 |
102 // Navigate to a page URL that doesn't belong to Instant renderer. | 84 // Navigate to a page URL that doesn't belong to Instant renderer. |
103 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return | |
104 // immediately without dispatching any message to the renderer. | |
105 NavigateAndCommit(GURL("http://www.example.com")); | 85 NavigateAndCommit(GURL("http://www.example.com")); |
106 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0); | |
107 | 86 |
108 search_tab()->DetermineIfPageSupportsInstant(); | |
109 EXPECT_FALSE(SupportsInstant()); | 87 EXPECT_FALSE(SupportsInstant()); |
110 } | 88 } |
111 | 89 |
112 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message | |
113 // reply handler updates the instant support state in InstantTab. | |
114 TEST_F(InstantTabTest, PageSupportsInstant) { | 90 TEST_F(InstantTabTest, PageSupportsInstant) { |
115 page.reset(new InstantTab(&delegate, web_contents())); | 91 page.reset(new InstantTab(&delegate, web_contents())); |
116 EXPECT_FALSE(SupportsInstant()); | 92 EXPECT_FALSE(SupportsInstant()); |
117 page->Init(); | 93 page->Init(); |
118 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 94 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
119 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); | |
120 search_tab()->DetermineIfPageSupportsInstant(); | |
121 | 95 |
122 // Assume the page supports instant. Invoke the message reply handler to make | 96 // Assume the page supports instant. Invoke the message reply handler to make |
123 // sure the InstantTab is notified about the instant support state. | 97 // sure the InstantTab is notified about the instant support state. |
124 const content::NavigationEntry* entry = | 98 const content::NavigationEntry* entry = |
125 web_contents()->GetController().GetLastCommittedEntry(); | 99 web_contents()->GetController().GetLastCommittedEntry(); |
126 EXPECT_TRUE(entry); | 100 EXPECT_TRUE(entry); |
127 search_tab()->InstantSupportChanged(true); | 101 search_tab()->InstantSupportChanged(true); |
128 EXPECT_TRUE(SupportsInstant()); | 102 EXPECT_TRUE(SupportsInstant()); |
129 } | 103 } |
OLD | NEW |