Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/ui/search/instant_tab_unittest.cc

Issue 2376633002: Small cleanup in SearchTabHelper (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } // namespace 43 } // namespace
44 44
45 class InstantTabTest : public ChromeRenderViewHostTestHarness { 45 class InstantTabTest : public ChromeRenderViewHostTestHarness {
46 public: 46 public:
47 void SetUp() override; 47 void SetUp() override;
48 48
49 SearchTabHelper* search_tab() { 49 SearchTabHelper* search_tab() {
50 return SearchTabHelper::FromWebContents(web_contents()); 50 return SearchTabHelper::FromWebContents(web_contents());
51 } 51 }
52 52
53 bool SupportsInstant() {
54 return search_tab()->model()->instant_support() == INSTANT_SUPPORT_YES;
55 }
56
53 std::unique_ptr<InstantTab> page; 57 std::unique_ptr<InstantTab> page;
54 FakePageDelegate delegate; 58 FakePageDelegate delegate;
55 }; 59 };
56 60
57 void InstantTabTest::SetUp() { 61 void InstantTabTest::SetUp() {
58 ChromeRenderViewHostTestHarness::SetUp(); 62 ChromeRenderViewHostTestHarness::SetUp();
59 SearchTabHelper::CreateForWebContents(web_contents()); 63 SearchTabHelper::CreateForWebContents(web_contents());
60 } 64 }
61 65
62 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) { 66 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
63 page.reset(new InstantTab(&delegate, web_contents())); 67 page.reset(new InstantTab(&delegate, web_contents()));
64 EXPECT_FALSE(search_tab()->SupportsInstant()); 68 EXPECT_FALSE(SupportsInstant());
65 page->Init(); 69 page->Init();
66 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 70 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
67 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)); 71 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
68 SearchTabHelper::FromWebContents(web_contents())-> 72 search_tab()->DetermineIfPageSupportsInstant();
69 DetermineIfPageSupportsInstant(); 73 EXPECT_TRUE(SupportsInstant());
70 EXPECT_TRUE(search_tab()->SupportsInstant());
71 } 74 }
72 75
73 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { 76 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) {
74 page.reset(new InstantTab(&delegate, web_contents())); 77 page.reset(new InstantTab(&delegate, web_contents()));
75 EXPECT_FALSE(search_tab()->SupportsInstant()); 78 EXPECT_FALSE(SupportsInstant());
76 page->Init(); 79 page->Init();
77 NavigateAndCommit(GURL("chrome-search://foo/bar")); 80 NavigateAndCommit(GURL("chrome-search://foo/bar"));
78 process()->sink().ClearMessages(); 81 process()->sink().ClearMessages();
79 SearchTabHelper::FromWebContents(web_contents())-> 82 search_tab()->DetermineIfPageSupportsInstant();
80 DetermineIfPageSupportsInstant();
81 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 83 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
82 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 84 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
83 ASSERT_TRUE(message != NULL); 85 ASSERT_TRUE(message != NULL);
84 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), 86 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(),
85 message->routing_id()); 87 message->routing_id());
86 } 88 }
87 89
88 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { 90 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
89 page.reset(new InstantTab(&delegate, web_contents())); 91 page.reset(new InstantTab(&delegate, web_contents()));
90 EXPECT_FALSE(search_tab()->SupportsInstant()); 92 EXPECT_FALSE(SupportsInstant());
91 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 93 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
92 page->Init(); 94 page->Init();
93 95
94 // Navigate to a page URL that doesn't belong to Instant renderer. 96 // Navigate to a page URL that doesn't belong to Instant renderer.
95 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return 97 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return
96 // immediately without dispatching any message to the renderer. 98 // immediately without dispatching any message to the renderer.
97 NavigateAndCommit(GURL("http://www.example.com")); 99 NavigateAndCommit(GURL("http://www.example.com"));
98 process()->sink().ClearMessages(); 100 process()->sink().ClearMessages();
99 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)); 101 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
100 102
101 SearchTabHelper::FromWebContents(web_contents())-> 103 search_tab()->DetermineIfPageSupportsInstant();
102 DetermineIfPageSupportsInstant();
103 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 104 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
104 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 105 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
105 ASSERT_TRUE(message == NULL); 106 ASSERT_TRUE(message == NULL);
106 EXPECT_FALSE(search_tab()->SupportsInstant()); 107 EXPECT_FALSE(SupportsInstant());
107 } 108 }
108 109
109 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message 110 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
110 // reply handler updates the instant support state in InstantTab. 111 // reply handler updates the instant support state in InstantTab.
111 TEST_F(InstantTabTest, PageSupportsInstant) { 112 TEST_F(InstantTabTest, PageSupportsInstant) {
112 page.reset(new InstantTab(&delegate, web_contents())); 113 page.reset(new InstantTab(&delegate, web_contents()));
113 EXPECT_FALSE(search_tab()->SupportsInstant()); 114 EXPECT_FALSE(SupportsInstant());
114 page->Init(); 115 page->Init();
115 NavigateAndCommit(GURL("chrome-search://foo/bar")); 116 NavigateAndCommit(GURL("chrome-search://foo/bar"));
116 process()->sink().ClearMessages(); 117 process()->sink().ClearMessages();
117 SearchTabHelper::FromWebContents(web_contents())-> 118 search_tab()->DetermineIfPageSupportsInstant();
118 DetermineIfPageSupportsInstant();
119 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 119 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
120 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 120 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
121 ASSERT_TRUE(message != NULL); 121 ASSERT_TRUE(message != NULL);
122 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(), 122 EXPECT_EQ(web_contents()->GetRenderViewHost()->GetRoutingID(),
123 message->routing_id()); 123 message->routing_id());
124 124
125 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)); 125 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
126 126
127 // Assume the page supports instant. Invoke the message reply handler to make 127 // Assume the page supports instant. Invoke the message reply handler to make
128 // sure the InstantTab is notified about the instant support state. 128 // sure the InstantTab is notified about the instant support state.
129 const content::NavigationEntry* entry = 129 const content::NavigationEntry* entry =
130 web_contents()->GetController().GetLastCommittedEntry(); 130 web_contents()->GetController().GetLastCommittedEntry();
131 EXPECT_TRUE(entry); 131 EXPECT_TRUE(entry);
132 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true); 132 search_tab()->InstantSupportChanged(true);
133 EXPECT_TRUE(search_tab()->SupportsInstant()); 133 EXPECT_TRUE(SupportsInstant());
134 } 134 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/search_tab_helper.h » ('j') | chrome/browser/ui/search/search_tab_helper.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698