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

Side by Side Diff: content/browser/webui/web_ui_unittest.cc

Issue 6814029: Revert 80519 - Move favicon from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/tab_contents/tab_contents_observer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/favicon_tab_helper.h"
6 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
7 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
8 #include "chrome/browser/ui/webui/new_tab_ui.h" 5 #include "chrome/browser/ui/webui/new_tab_ui.h"
9 #include "chrome/common/url_constants.h" 6 #include "chrome/common/url_constants.h"
10 #include "chrome/test/testing_profile.h" 7 #include "chrome/test/testing_profile.h"
11 #include "content/browser/browser_thread.h" 8 #include "content/browser/browser_thread.h"
9 #include "content/browser/renderer_host/test_render_view_host.h"
12 #include "content/browser/site_instance.h" 10 #include "content/browser/site_instance.h"
13 #include "content/browser/tab_contents/navigation_controller.h" 11 #include "content/browser/tab_contents/navigation_controller.h"
14 #include "content/browser/tab_contents/test_tab_contents.h" 12 #include "content/browser/tab_contents/test_tab_contents.h"
15 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
16 14
17 class WebUITest : public TabContentsWrapperTestHarness { 15 class WebUITest : public RenderViewHostTestHarness {
18 public: 16 public:
19 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} 17 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}
20 18
21 // Tests navigating with a Web UI from a fresh (nothing pending or committed) 19 // Tests navigating with a Web UI from a fresh (nothing pending or committed)
22 // state, through pending, committed, then another navigation. The first page 20 // state, through pending, committed, then another navigation. The first page
23 // ID that we should use is passed as a parameter. We'll use the next two 21 // ID that we should use is passed as a parameter. We'll use the next two
24 // values. This must be increasing for the life of the tests. 22 // values. This must be increasing for the life of the tests.
25 static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { 23 static void DoNavigationTest(TabContents* contents, int page_id) {
26 TabContents* contents = wrapper->tab_contents();
27 NavigationController* controller = &contents->controller(); 24 NavigationController* controller = &contents->controller();
28 25
29 // Start a pending load. 26 // Start a pending load.
30 GURL new_tab_url(chrome::kChromeUINewTabURL); 27 GURL new_tab_url(chrome::kChromeUINewTabURL);
31 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); 28 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK);
32 29
33 // The navigation entry should be pending with no committed entry. 30 // The navigation entry should be pending with no committed entry.
34 ASSERT_TRUE(controller->pending_entry()); 31 ASSERT_TRUE(controller->pending_entry());
35 ASSERT_FALSE(controller->GetLastCommittedEntry()); 32 ASSERT_FALSE(controller->GetLastCommittedEntry());
36 33
37 // Check the things the pending Web UI should have set. 34 // Check the things the pending Web UI should have set.
38 EXPECT_FALSE(contents->ShouldDisplayURL()); 35 EXPECT_FALSE(contents->ShouldDisplayURL());
39 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 36 EXPECT_FALSE(contents->ShouldDisplayFavicon());
40 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); 37 EXPECT_TRUE(contents->ShouldShowBookmarkBar());
41 EXPECT_TRUE(contents->FocusLocationBarByDefault()); 38 EXPECT_TRUE(contents->FocusLocationBarByDefault());
42 39
43 // Now commit the load. 40 // Now commit the load.
44 static_cast<TestRenderViewHost*>( 41 static_cast<TestRenderViewHost*>(
45 contents->render_view_host())->SendNavigate(page_id, new_tab_url); 42 contents->render_view_host())->SendNavigate(page_id, new_tab_url);
46 43
47 // The same flags should be set as before now that the load has committed. 44 // The same flags should be set as before now that the load has committed.
48 EXPECT_FALSE(contents->ShouldDisplayURL()); 45 EXPECT_FALSE(contents->ShouldDisplayURL());
49 EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 46 EXPECT_FALSE(contents->ShouldDisplayFavicon());
50 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); 47 EXPECT_TRUE(contents->ShouldShowBookmarkBar());
51 EXPECT_TRUE(contents->FocusLocationBarByDefault()); 48 EXPECT_TRUE(contents->FocusLocationBarByDefault());
52 49
53 // Start a pending navigation to a regular page. 50 // Start a pending navigation to a regular page.
54 GURL next_url("http://google.com/"); 51 GURL next_url("http://google.com/");
55 controller->LoadURL(next_url, GURL(), PageTransition::LINK); 52 controller->LoadURL(next_url, GURL(), PageTransition::LINK);
56 53
57 // Check the flags. Some should reflect the new page (URL, title), some 54 // Check the flags. Some should reflect the new page (URL, title), some
58 // should reflect the old one (bookmark bar) until it has committed. 55 // should reflect the old one (bookmark bar) until it has committed.
59 EXPECT_TRUE(contents->ShouldDisplayURL()); 56 EXPECT_TRUE(contents->ShouldDisplayURL());
60 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 57 EXPECT_TRUE(contents->ShouldDisplayFavicon());
61 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); 58 EXPECT_TRUE(contents->ShouldShowBookmarkBar());
62 EXPECT_FALSE(contents->FocusLocationBarByDefault()); 59 EXPECT_FALSE(contents->FocusLocationBarByDefault());
63 60
64 // Commit the regular page load. Note that we must send it to the "pending" 61 // Commit the regular page load. Note that we must send it to the "pending"
65 // RenderViewHost if there is one, since this transition will also cause a 62 // RenderViewHost if there is one, since this transition will also cause a
66 // process transition, and our RVH pointer will be the "committed" one. 63 // process transition, and our RVH pointer will be the "committed" one.
67 // In the second call to this function from WebUIToStandard, it won't 64 // In the second call to this function from WebUIToStandard, it won't
68 // actually be pending, which is the point of this test. 65 // actually be pending, which is the point of this test.
69 if (contents->render_manager()->pending_render_view_host()) { 66 if (contents->render_manager()->pending_render_view_host()) {
70 static_cast<TestRenderViewHost*>( 67 static_cast<TestRenderViewHost*>(
71 contents->render_manager()->pending_render_view_host())->SendNavigate( 68 contents->render_manager()->pending_render_view_host())->SendNavigate(
72 page_id + 1, next_url); 69 page_id + 1, next_url);
73 } else { 70 } else {
74 static_cast<TestRenderViewHost*>( 71 static_cast<TestRenderViewHost*>(
75 contents->render_view_host())->SendNavigate(page_id + 1, next_url); 72 contents->render_view_host())->SendNavigate(page_id + 1, next_url);
76 } 73 }
77 74
78 // The state should now reflect a regular page. 75 // The state should now reflect a regular page.
79 EXPECT_TRUE(contents->ShouldDisplayURL()); 76 EXPECT_TRUE(contents->ShouldDisplayURL());
80 EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); 77 EXPECT_TRUE(contents->ShouldDisplayFavicon());
81 EXPECT_FALSE(contents->ShouldShowBookmarkBar()); 78 EXPECT_FALSE(contents->ShouldShowBookmarkBar());
82 EXPECT_FALSE(contents->FocusLocationBarByDefault()); 79 EXPECT_FALSE(contents->FocusLocationBarByDefault());
83 } 80 }
84 81
85 private: 82 private:
86 BrowserThread ui_thread_; 83 BrowserThread ui_thread_;
87 84
88 DISALLOW_COPY_AND_ASSIGN(WebUITest); 85 DISALLOW_COPY_AND_ASSIGN(WebUITest);
89 }; 86 };
90 87
91 // Tests that the New Tab Page flags are correctly set and propogated by 88 // Tests that the New Tab Page flags are correctly set and propogated by
92 // TabContents when we first navigate to a Web UI page, then to a standard 89 // TabContents when we first navigate to a Web UI page, then to a standard
93 // non-DOM-UI page. 90 // non-DOM-UI page.
94 TEST_F(WebUITest, WebUIToStandard) { 91 TEST_F(WebUITest, WebUIToStandard) {
95 DoNavigationTest(contents_wrapper(), 1); 92 DoNavigationTest(contents(), 1);
96 93
97 // Test the case where we're not doing the initial navigation. This is 94 // Test the case where we're not doing the initial navigation. This is
98 // slightly different than the very-first-navigation case since the 95 // slightly different than the very-first-navigation case since the
99 // SiteInstance will be the same (the original TabContents must still be 96 // SiteInstance will be the same (the original TabContents must still be
100 // alive), which will trigger different behavior in RenderViewHostManager. 97 // alive), which will trigger different behavior in RenderViewHostManager.
101 TestTabContents* contents2 = new TestTabContents(profile_.get(), NULL); 98 TestTabContents contents2(profile_.get(), NULL);
102 TabContentsWrapper wrapper2(contents2);
103 99
104 DoNavigationTest(&wrapper2, 101); 100 DoNavigationTest(&contents2, 101);
105 } 101 }
106 102
107 TEST_F(WebUITest, WebUIToWebUI) { 103 TEST_F(WebUITest, WebUIToWebUI) {
108 // Do a load (this state is tested above). 104 // Do a load (this state is tested above).
109 GURL new_tab_url(chrome::kChromeUINewTabURL); 105 GURL new_tab_url(chrome::kChromeUINewTabURL);
110 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); 106 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
111 rvh()->SendNavigate(1, new_tab_url); 107 rvh()->SendNavigate(1, new_tab_url);
112 108
113 // Start another pending load of the new tab page. 109 // Start another pending load of the new tab page.
114 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); 110 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
115 rvh()->SendNavigate(2, new_tab_url); 111 rvh()->SendNavigate(2, new_tab_url);
116 112
117 // The flags should be the same as the non-pending state. 113 // The flags should be the same as the non-pending state.
118 EXPECT_FALSE(contents()->ShouldDisplayURL()); 114 EXPECT_FALSE(contents()->ShouldDisplayURL());
119 EXPECT_FALSE( 115 EXPECT_FALSE(contents()->ShouldDisplayFavicon());
120 contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon());
121 EXPECT_TRUE(contents()->ShouldShowBookmarkBar()); 116 EXPECT_TRUE(contents()->ShouldShowBookmarkBar());
122 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); 117 EXPECT_TRUE(contents()->FocusLocationBarByDefault());
123 } 118 }
124 119
125 TEST_F(WebUITest, StandardToWebUI) { 120 TEST_F(WebUITest, StandardToWebUI) {
126 // Start a pending navigation to a regular page. 121 // Start a pending navigation to a regular page.
127 GURL std_url("http://google.com/"); 122 GURL std_url("http://google.com/");
128 123
129 controller().LoadURL(std_url, GURL(), PageTransition::LINK); 124 controller().LoadURL(std_url, GURL(), PageTransition::LINK);
130 125
131 // The state should now reflect the default. 126 // The state should now reflect the default.
132 EXPECT_TRUE(contents()->ShouldDisplayURL()); 127 EXPECT_TRUE(contents()->ShouldDisplayURL());
133 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 128 EXPECT_TRUE(contents()->ShouldDisplayFavicon());
134 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); 129 EXPECT_FALSE(contents()->ShouldShowBookmarkBar());
135 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); 130 EXPECT_FALSE(contents()->FocusLocationBarByDefault());
136 131
137 // Commit the load, the state should be the same. 132 // Commit the load, the state should be the same.
138 rvh()->SendNavigate(1, std_url); 133 rvh()->SendNavigate(1, std_url);
139 EXPECT_TRUE(contents()->ShouldDisplayURL()); 134 EXPECT_TRUE(contents()->ShouldDisplayURL());
140 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 135 EXPECT_TRUE(contents()->ShouldDisplayFavicon());
141 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); 136 EXPECT_FALSE(contents()->ShouldShowBookmarkBar());
142 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); 137 EXPECT_FALSE(contents()->FocusLocationBarByDefault());
143 138
144 // Start a pending load for a WebUI. 139 // Start a pending load for a WebUI.
145 GURL new_tab_url(chrome::kChromeUINewTabURL); 140 GURL new_tab_url(chrome::kChromeUINewTabURL);
146 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); 141 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
147 EXPECT_FALSE(contents()->ShouldDisplayURL()); 142 EXPECT_FALSE(contents()->ShouldDisplayURL());
148 EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); 143 EXPECT_TRUE(contents()->ShouldDisplayFavicon());
149 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); 144 EXPECT_FALSE(contents()->ShouldShowBookmarkBar());
150 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); 145 EXPECT_TRUE(contents()->FocusLocationBarByDefault());
151 146
152 // Committing Web UI is tested above. 147 // Committing Web UI is tested above.
153 } 148 }
154 149
155 class TabContentsForFocusTest : public TestTabContents { 150 class TabContentsForFocusTest : public TestTabContents {
156 public: 151 public:
157 TabContentsForFocusTest(Profile* profile, SiteInstance* instance) 152 TabContentsForFocusTest(Profile* profile, SiteInstance* instance)
158 : TestTabContents(profile, instance), focus_called_(0) { 153 : TestTabContents(profile, instance), focus_called_(0) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 pending_rvh()->SendNavigate(page_id, new_tab_url); 187 pending_rvh()->SendNavigate(page_id, new_tab_url);
193 EXPECT_LT(focus_called, tc->focus_called()); 188 EXPECT_LT(focus_called, tc->focus_called());
194 189
195 // Navigate forward. Shouldn't focus the location bar. 190 // Navigate forward. Shouldn't focus the location bar.
196 focus_called = tc->focus_called(); 191 focus_called = tc->focus_called();
197 ASSERT_TRUE(controller().CanGoForward()); 192 ASSERT_TRUE(controller().CanGoForward());
198 controller().GoForward(); 193 controller().GoForward();
199 pending_rvh()->SendNavigate(next_page_id, next_url); 194 pending_rvh()->SendNavigate(next_page_id, next_url);
200 EXPECT_EQ(focus_called, tc->focus_called()); 195 EXPECT_EQ(focus_called, tc->focus_called());
201 } 196 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/tab_contents_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698