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

Side by Side Diff: chrome/browser/dom_ui/web_ui_unittest.cc

Issue 6480046: WebUI: Change more references to WebUI in dom_ui directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 | « chrome/browser/dom_ui/web_ui_theme_source_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | 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/browser_thread.h" 5 #include "chrome/browser/browser_thread.h"
6 #include "chrome/browser/dom_ui/new_tab_ui.h" 6 #include "chrome/browser/dom_ui/new_tab_ui.h"
7 #include "chrome/browser/renderer_host/site_instance.h" 7 #include "chrome/browser/renderer_host/site_instance.h"
8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
9 #include "chrome/browser/tab_contents/navigation_controller.h" 9 #include "chrome/browser/tab_contents/navigation_controller.h"
10 #include "chrome/browser/tab_contents/test_tab_contents.h" 10 #include "chrome/browser/tab_contents/test_tab_contents.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/testing_profile.h" 12 #include "chrome/test/testing_profile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 class DOMUITest : public RenderViewHostTestHarness { 15 class WebUITest : public RenderViewHostTestHarness {
16 public: 16 public:
17 DOMUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} 17 WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {}
18 18
19 // 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)
20 // state, through pending, committed, then another navigation. The first page 20 // state, through pending, committed, then another navigation. The first page
21 // 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
22 // values. This must be increasing for the life of the tests. 22 // values. This must be increasing for the life of the tests.
23 static void DoNavigationTest(TabContents* contents, int page_id) { 23 static void DoNavigationTest(TabContents* contents, int page_id) {
24 NavigationController* controller = &contents->controller(); 24 NavigationController* controller = &contents->controller();
25 25
26 // Start a pending load. 26 // Start a pending load.
27 GURL new_tab_url(chrome::kChromeUINewTabURL); 27 GURL new_tab_url(chrome::kChromeUINewTabURL);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // The state should now reflect a regular page. 75 // The state should now reflect a regular page.
76 EXPECT_TRUE(contents->ShouldDisplayURL()); 76 EXPECT_TRUE(contents->ShouldDisplayURL());
77 EXPECT_TRUE(contents->ShouldDisplayFavIcon()); 77 EXPECT_TRUE(contents->ShouldDisplayFavIcon());
78 EXPECT_FALSE(contents->ShouldShowBookmarkBar()); 78 EXPECT_FALSE(contents->ShouldShowBookmarkBar());
79 EXPECT_FALSE(contents->FocusLocationBarByDefault()); 79 EXPECT_FALSE(contents->FocusLocationBarByDefault());
80 } 80 }
81 81
82 private: 82 private:
83 BrowserThread ui_thread_; 83 BrowserThread ui_thread_;
84 84
85 DISALLOW_COPY_AND_ASSIGN(DOMUITest); 85 DISALLOW_COPY_AND_ASSIGN(WebUITest);
86 }; 86 };
87 87
88 // 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
89 // 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
90 // non-DOM-UI page. 90 // non-DOM-UI page.
91 TEST_F(DOMUITest, WebUIToStandard) { 91 TEST_F(WebUITest, WebUIToStandard) {
92 DoNavigationTest(contents(), 1); 92 DoNavigationTest(contents(), 1);
93 93
94 // 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
95 // slightly different than the very-first-navigation case since the 95 // slightly different than the very-first-navigation case since the
96 // SiteInstance will be the same (the original TabContents must still be 96 // SiteInstance will be the same (the original TabContents must still be
97 // alive), which will trigger different behavior in RenderViewHostManager. 97 // alive), which will trigger different behavior in RenderViewHostManager.
98 TestTabContents contents2(profile_.get(), NULL); 98 TestTabContents contents2(profile_.get(), NULL);
99 99
100 DoNavigationTest(&contents2, 101); 100 DoNavigationTest(&contents2, 101);
101 } 101 }
102 102
103 TEST_F(DOMUITest, DOMUIToDOMUI) { 103 TEST_F(WebUITest, WebUIToWebUI) {
104 // Do a load (this state is tested above). 104 // Do a load (this state is tested above).
105 GURL new_tab_url(chrome::kChromeUINewTabURL); 105 GURL new_tab_url(chrome::kChromeUINewTabURL);
106 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); 106 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
107 rvh()->SendNavigate(1, new_tab_url); 107 rvh()->SendNavigate(1, new_tab_url);
108 108
109 // Start another pending load of the new tab page. 109 // Start another pending load of the new tab page.
110 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); 110 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK);
111 rvh()->SendNavigate(2, new_tab_url); 111 rvh()->SendNavigate(2, new_tab_url);
112 112
113 // The flags should be the same as the non-pending state. 113 // The flags should be the same as the non-pending state.
114 EXPECT_FALSE(contents()->ShouldDisplayURL()); 114 EXPECT_FALSE(contents()->ShouldDisplayURL());
115 EXPECT_FALSE(contents()->ShouldDisplayFavIcon()); 115 EXPECT_FALSE(contents()->ShouldDisplayFavIcon());
116 EXPECT_TRUE(contents()->ShouldShowBookmarkBar()); 116 EXPECT_TRUE(contents()->ShouldShowBookmarkBar());
117 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); 117 EXPECT_TRUE(contents()->FocusLocationBarByDefault());
118 } 118 }
119 119
120 TEST_F(DOMUITest, StandardToDOMUI) { 120 TEST_F(WebUITest, StandardToWebUI) {
121 // Start a pending navigation to a regular page. 121 // Start a pending navigation to a regular page.
122 GURL std_url("http://google.com/"); 122 GURL std_url("http://google.com/");
123 123
124 controller().LoadURL(std_url, GURL(), PageTransition::LINK); 124 controller().LoadURL(std_url, GURL(), PageTransition::LINK);
125 125
126 // The state should now reflect the default. 126 // The state should now reflect the default.
127 EXPECT_TRUE(contents()->ShouldDisplayURL()); 127 EXPECT_TRUE(contents()->ShouldDisplayURL());
128 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); 128 EXPECT_TRUE(contents()->ShouldDisplayFavIcon());
129 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); 129 EXPECT_FALSE(contents()->ShouldShowBookmarkBar());
130 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); 130 EXPECT_FALSE(contents()->FocusLocationBarByDefault());
(...skipping 22 matching lines...) Expand all
153 : TestTabContents(profile, instance), focus_called_(0) { 153 : TestTabContents(profile, instance), focus_called_(0) {
154 } 154 }
155 155
156 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } 156 virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; }
157 int focus_called() const { return focus_called_; } 157 int focus_called() const { return focus_called_; }
158 158
159 private: 159 private:
160 int focus_called_; 160 int focus_called_;
161 }; 161 };
162 162
163 TEST_F(DOMUITest, FocusOnNavigate) { 163 TEST_F(WebUITest, FocusOnNavigate) {
164 // Setup. |tc| will be used to track when we try to focus the location bar. 164 // Setup. |tc| will be used to track when we try to focus the location bar.
165 TabContentsForFocusTest* tc = new TabContentsForFocusTest( 165 TabContentsForFocusTest* tc = new TabContentsForFocusTest(
166 contents()->profile(), 166 contents()->profile(),
167 SiteInstance::CreateSiteInstance(contents()->profile())); 167 SiteInstance::CreateSiteInstance(contents()->profile()));
168 tc->controller().CopyStateFrom(controller()); 168 tc->controller().CopyStateFrom(controller());
169 scoped_ptr<TestTabContents> tc_scoped_ptr(tc); 169 scoped_ptr<TestTabContents> tc_scoped_ptr(tc);
170 contents_.swap(tc_scoped_ptr); 170 contents_.swap(tc_scoped_ptr);
171 int page_id = 200; 171 int page_id = 200;
172 172
173 // Load the NTP. 173 // Load the NTP.
(...skipping 16 matching lines...) Expand all
190 190
191 // Navigate forward. Shouldn't focus the location bar. 191 // Navigate forward. Shouldn't focus the location bar.
192 focus_called = tc->focus_called(); 192 focus_called = tc->focus_called();
193 ASSERT_TRUE(controller().CanGoForward()); 193 ASSERT_TRUE(controller().CanGoForward());
194 controller().GoForward(); 194 controller().GoForward();
195 pending_rvh()->SendNavigate(next_page_id, next_url); 195 pending_rvh()->SendNavigate(next_page_id, next_url);
196 EXPECT_EQ(focus_called, tc->focus_called()); 196 EXPECT_EQ(focus_called, tc->focus_called());
197 197
198 contents_.swap(tc_scoped_ptr); 198 contents_.swap(tc_scoped_ptr);
199 } 199 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/web_ui_theme_source_unittest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698