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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 class Profile; | 30 class Profile; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 class FakePageDelegate : public InstantTab::Delegate { | 34 class FakePageDelegate : public InstantTab::Delegate { |
35 public: | 35 public: |
36 virtual ~FakePageDelegate() { | 36 virtual ~FakePageDelegate() { |
37 } | 37 } |
38 | 38 |
39 MOCK_METHOD2(InstantSupportDetermined, | |
40 void(const content::WebContents* contents, | |
41 bool supports_instant)); | |
42 MOCK_METHOD2(InstantTabAboutToNavigateMainFrame, | 39 MOCK_METHOD2(InstantTabAboutToNavigateMainFrame, |
43 void(const content::WebContents* contents, const GURL& url)); | 40 void(const content::WebContents* contents, const GURL& url)); |
44 }; | 41 }; |
45 | 42 |
46 class MockSearchBoxClientFactory | 43 class MockSearchBoxClientFactory |
47 : public SearchIPCRouter::SearchBoxClientFactory { | 44 : public SearchIPCRouter::SearchBoxClientFactory { |
48 public: | 45 public: |
49 MOCK_METHOD0(GetSearchBox, chrome::mojom::SearchBox*(void)); | 46 MOCK_METHOD0(GetSearchBox, chrome::mojom::SearchBox*(void)); |
50 }; | 47 }; |
51 | 48 |
(...skipping 24 matching lines...) Expand all Loading... |
76 search_tab() | 73 search_tab() |
77 ->ipc_router_for_testing() | 74 ->ipc_router_for_testing() |
78 .set_search_box_client_factory_for_testing(std::move(factory)); | 75 .set_search_box_client_factory_for_testing(std::move(factory)); |
79 } | 76 } |
80 | 77 |
81 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) { | 78 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) { |
82 page.reset(new InstantTab(&delegate, web_contents())); | 79 page.reset(new InstantTab(&delegate, web_contents())); |
83 EXPECT_FALSE(SupportsInstant()); | 80 EXPECT_FALSE(SupportsInstant()); |
84 page->Init(); | 81 page->Init(); |
85 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 82 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
86 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)); | |
87 search_tab()->DetermineIfPageSupportsInstant(); | 83 search_tab()->DetermineIfPageSupportsInstant(); |
88 EXPECT_TRUE(SupportsInstant()); | 84 EXPECT_TRUE(SupportsInstant()); |
89 } | 85 } |
90 | 86 |
91 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { | 87 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { |
92 page.reset(new InstantTab(&delegate, web_contents())); | 88 page.reset(new InstantTab(&delegate, web_contents())); |
93 EXPECT_FALSE(SupportsInstant()); | 89 EXPECT_FALSE(SupportsInstant()); |
94 page->Init(); | 90 page->Init(); |
95 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 91 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
96 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); | 92 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); |
97 search_tab()->DetermineIfPageSupportsInstant(); | 93 search_tab()->DetermineIfPageSupportsInstant(); |
98 } | 94 } |
99 | 95 |
100 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { | 96 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { |
101 page.reset(new InstantTab(&delegate, web_contents())); | 97 page.reset(new InstantTab(&delegate, web_contents())); |
102 EXPECT_FALSE(SupportsInstant()); | 98 EXPECT_FALSE(SupportsInstant()); |
103 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 99 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
104 page->Init(); | 100 page->Init(); |
105 | 101 |
106 // Navigate to a page URL that doesn't belong to Instant renderer. | 102 // Navigate to a page URL that doesn't belong to Instant renderer. |
107 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return | 103 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return |
108 // immediately without dispatching any message to the renderer. | 104 // immediately without dispatching any message to the renderer. |
109 NavigateAndCommit(GURL("http://www.example.com")); | 105 NavigateAndCommit(GURL("http://www.example.com")); |
110 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)); | |
111 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0); | 106 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0); |
112 | 107 |
113 search_tab()->DetermineIfPageSupportsInstant(); | 108 search_tab()->DetermineIfPageSupportsInstant(); |
114 EXPECT_FALSE(SupportsInstant()); | 109 EXPECT_FALSE(SupportsInstant()); |
115 } | 110 } |
116 | 111 |
117 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message | 112 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message |
118 // reply handler updates the instant support state in InstantTab. | 113 // reply handler updates the instant support state in InstantTab. |
119 TEST_F(InstantTabTest, PageSupportsInstant) { | 114 TEST_F(InstantTabTest, PageSupportsInstant) { |
120 page.reset(new InstantTab(&delegate, web_contents())); | 115 page.reset(new InstantTab(&delegate, web_contents())); |
121 EXPECT_FALSE(SupportsInstant()); | 116 EXPECT_FALSE(SupportsInstant()); |
122 page->Init(); | 117 page->Init(); |
123 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 118 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
124 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); | 119 EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()); |
125 search_tab()->DetermineIfPageSupportsInstant(); | 120 search_tab()->DetermineIfPageSupportsInstant(); |
126 | 121 |
127 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)); | |
128 | |
129 // Assume the page supports instant. Invoke the message reply handler to make | 122 // Assume the page supports instant. Invoke the message reply handler to make |
130 // sure the InstantTab is notified about the instant support state. | 123 // sure the InstantTab is notified about the instant support state. |
131 const content::NavigationEntry* entry = | 124 const content::NavigationEntry* entry = |
132 web_contents()->GetController().GetLastCommittedEntry(); | 125 web_contents()->GetController().GetLastCommittedEntry(); |
133 EXPECT_TRUE(entry); | 126 EXPECT_TRUE(entry); |
134 search_tab()->InstantSupportChanged(true); | 127 search_tab()->InstantSupportChanged(true); |
135 EXPECT_TRUE(SupportsInstant()); | 128 EXPECT_TRUE(SupportsInstant()); |
136 } | 129 } |
OLD | NEW |