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