| 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_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 std::unique_ptr<InstantPage> page; | 61 std::unique_ptr<InstantPage> page; |
| 62 FakePageDelegate delegate; | 62 FakePageDelegate delegate; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 void InstantPageTest::SetUp() { | 65 void InstantPageTest::SetUp() { |
| 66 ChromeRenderViewHostTestHarness::SetUp(); | 66 ChromeRenderViewHostTestHarness::SetUp(); |
| 67 SearchTabHelper::CreateForWebContents(web_contents()); | 67 SearchTabHelper::CreateForWebContents(web_contents()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(InstantPageTest, IsLocal) { | 70 TEST_F(InstantPageTest, IsLocal) { |
| 71 page.reset(new InstantPage(&delegate, "", NULL)); | 71 page.reset(new InstantPage(&delegate)); |
| 72 EXPECT_FALSE(page->supports_instant()); | 72 EXPECT_FALSE(page->supports_instant()); |
| 73 EXPECT_FALSE(page->IsLocal()); | 73 EXPECT_FALSE(page->IsLocal()); |
| 74 page->SetContents(web_contents()); | 74 page->SetContents(web_contents()); |
| 75 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 75 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 76 EXPECT_TRUE(page->IsLocal()); | 76 EXPECT_TRUE(page->IsLocal()); |
| 77 NavigateAndCommit(GURL("http://example.com")); | 77 NavigateAndCommit(GURL("http://example.com")); |
| 78 EXPECT_FALSE(page->IsLocal()); | 78 EXPECT_FALSE(page->IsLocal()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { | 81 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { |
| 82 page.reset(new InstantPage(&delegate, "", NULL)); | 82 page.reset(new InstantPage(&delegate)); |
| 83 EXPECT_FALSE(page->supports_instant()); | 83 EXPECT_FALSE(page->supports_instant()); |
| 84 page->SetContents(web_contents()); | 84 page->SetContents(web_contents()); |
| 85 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 85 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 86 EXPECT_TRUE(page->IsLocal()); | 86 EXPECT_TRUE(page->IsLocal()); |
| 87 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) | 87 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) |
| 88 .Times(1); | 88 .Times(1); |
| 89 SearchTabHelper::FromWebContents(web_contents())-> | 89 SearchTabHelper::FromWebContents(web_contents())-> |
| 90 DetermineIfPageSupportsInstant(); | 90 DetermineIfPageSupportsInstant(); |
| 91 EXPECT_TRUE(page->supports_instant()); | 91 EXPECT_TRUE(page->supports_instant()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) { | 94 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) { |
| 95 page.reset(new InstantPage(&delegate, "", NULL)); | 95 page.reset(new InstantPage(&delegate)); |
| 96 EXPECT_FALSE(page->supports_instant()); | 96 EXPECT_FALSE(page->supports_instant()); |
| 97 page->SetContents(web_contents()); | 97 page->SetContents(web_contents()); |
| 98 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 98 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 99 EXPECT_FALSE(page->IsLocal()); | 99 EXPECT_FALSE(page->IsLocal()); |
| 100 process()->sink().ClearMessages(); | 100 process()->sink().ClearMessages(); |
| 101 SearchTabHelper::FromWebContents(web_contents())-> | 101 SearchTabHelper::FromWebContents(web_contents())-> |
| 102 DetermineIfPageSupportsInstant(); | 102 DetermineIfPageSupportsInstant(); |
| 103 const IPC::Message* message = process()->sink().GetFirstMessageMatching( | 103 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 104 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); | 104 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); |
| 105 ASSERT_TRUE(message != NULL); | 105 ASSERT_TRUE(message != NULL); |
| 106 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); | 106 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) { | 109 TEST_F(InstantPageTest, PageURLDoesntBelongToInstantRenderer) { |
| 110 page.reset(new InstantPage(&delegate, "", NULL)); | 110 page.reset(new InstantPage(&delegate)); |
| 111 EXPECT_FALSE(page->supports_instant()); | 111 EXPECT_FALSE(page->supports_instant()); |
| 112 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); | 112 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
| 113 page->SetContents(web_contents()); | 113 page->SetContents(web_contents()); |
| 114 | 114 |
| 115 // Navigate to a page URL that doesn't belong to Instant renderer. | 115 // Navigate to a page URL that doesn't belong to Instant renderer. |
| 116 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return | 116 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return |
| 117 // immediately without dispatching any message to the renderer. | 117 // immediately without dispatching any message to the renderer. |
| 118 NavigateAndCommit(GURL("http://www.example.com")); | 118 NavigateAndCommit(GURL("http://www.example.com")); |
| 119 EXPECT_FALSE(page->IsLocal()); | 119 EXPECT_FALSE(page->IsLocal()); |
| 120 process()->sink().ClearMessages(); | 120 process()->sink().ClearMessages(); |
| 121 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)) | 121 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)) |
| 122 .Times(1); | 122 .Times(1); |
| 123 | 123 |
| 124 SearchTabHelper::FromWebContents(web_contents())-> | 124 SearchTabHelper::FromWebContents(web_contents())-> |
| 125 DetermineIfPageSupportsInstant(); | 125 DetermineIfPageSupportsInstant(); |
| 126 const IPC::Message* message = process()->sink().GetFirstMessageMatching( | 126 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 127 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); | 127 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); |
| 128 ASSERT_TRUE(message == NULL); | 128 ASSERT_TRUE(message == NULL); |
| 129 EXPECT_FALSE(page->supports_instant()); | 129 EXPECT_FALSE(page->supports_instant()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message | 132 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message |
| 133 // reply handler updates the instant support state in InstantPage. | 133 // reply handler updates the instant support state in InstantPage. |
| 134 TEST_F(InstantPageTest, PageSupportsInstant) { | 134 TEST_F(InstantPageTest, PageSupportsInstant) { |
| 135 page.reset(new InstantPage(&delegate, "", NULL)); | 135 page.reset(new InstantPage(&delegate)); |
| 136 EXPECT_FALSE(page->supports_instant()); | 136 EXPECT_FALSE(page->supports_instant()); |
| 137 page->SetContents(web_contents()); | 137 page->SetContents(web_contents()); |
| 138 NavigateAndCommit(GURL("chrome-search://foo/bar")); | 138 NavigateAndCommit(GURL("chrome-search://foo/bar")); |
| 139 process()->sink().ClearMessages(); | 139 process()->sink().ClearMessages(); |
| 140 SearchTabHelper::FromWebContents(web_contents())-> | 140 SearchTabHelper::FromWebContents(web_contents())-> |
| 141 DetermineIfPageSupportsInstant(); | 141 DetermineIfPageSupportsInstant(); |
| 142 const IPC::Message* message = process()->sink().GetFirstMessageMatching( | 142 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 143 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); | 143 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); |
| 144 ASSERT_TRUE(message != NULL); | 144 ASSERT_TRUE(message != NULL); |
| 145 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); | 145 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); |
| 146 | 146 |
| 147 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) | 147 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) |
| 148 .Times(1); | 148 .Times(1); |
| 149 | 149 |
| 150 // Assume the page supports instant. Invoke the message reply handler to make | 150 // Assume the page supports instant. Invoke the message reply handler to make |
| 151 // sure the InstantPage is notified about the instant support state. | 151 // sure the InstantPage is notified about the instant support state. |
| 152 const content::NavigationEntry* entry = | 152 const content::NavigationEntry* entry = |
| 153 web_contents()->GetController().GetLastCommittedEntry(); | 153 web_contents()->GetController().GetLastCommittedEntry(); |
| 154 EXPECT_TRUE(entry); | 154 EXPECT_TRUE(entry); |
| 155 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true); | 155 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true); |
| 156 EXPECT_TRUE(page->supports_instant()); | 156 EXPECT_TRUE(page->supports_instant()); |
| 157 } | 157 } |
| OLD | NEW |