OLD | NEW |
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/ui/webui/new_tab_ui.h" | 5 #include "chrome/browser/ui/webui/new_tab_ui.h" |
6 #include "chrome/common/url_constants.h" | 6 #include "chrome/common/url_constants.h" |
7 #include "chrome/test/testing_profile.h" | 7 #include "chrome/test/testing_profile.h" |
8 #include "content/browser/browser_thread.h" | 8 #include "content/browser/browser_thread.h" |
9 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
10 #include "content/browser/site_instance.h" | 10 #include "content/browser/site_instance.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // Start a pending load. | 26 // Start a pending load. |
27 GURL new_tab_url(chrome::kChromeUINewTabURL); | 27 GURL new_tab_url(chrome::kChromeUINewTabURL); |
28 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 28 controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
29 | 29 |
30 // The navigation entry should be pending with no committed entry. | 30 // The navigation entry should be pending with no committed entry. |
31 ASSERT_TRUE(controller->pending_entry()); | 31 ASSERT_TRUE(controller->pending_entry()); |
32 ASSERT_FALSE(controller->GetLastCommittedEntry()); | 32 ASSERT_FALSE(controller->GetLastCommittedEntry()); |
33 | 33 |
34 // Check the things the pending Web UI should have set. | 34 // Check the things the pending Web UI should have set. |
35 EXPECT_FALSE(contents->ShouldDisplayURL()); | 35 EXPECT_FALSE(contents->ShouldDisplayURL()); |
36 EXPECT_FALSE(contents->ShouldDisplayFavIcon()); | 36 EXPECT_FALSE(contents->ShouldDisplayFavicon()); |
37 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); | 37 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); |
38 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 38 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
39 | 39 |
40 // Now commit the load. | 40 // Now commit the load. |
41 static_cast<TestRenderViewHost*>( | 41 static_cast<TestRenderViewHost*>( |
42 contents->render_view_host())->SendNavigate(page_id, new_tab_url); | 42 contents->render_view_host())->SendNavigate(page_id, new_tab_url); |
43 | 43 |
44 // 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. |
45 EXPECT_FALSE(contents->ShouldDisplayURL()); | 45 EXPECT_FALSE(contents->ShouldDisplayURL()); |
46 EXPECT_FALSE(contents->ShouldDisplayFavIcon()); | 46 EXPECT_FALSE(contents->ShouldDisplayFavicon()); |
47 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); | 47 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); |
48 EXPECT_TRUE(contents->FocusLocationBarByDefault()); | 48 EXPECT_TRUE(contents->FocusLocationBarByDefault()); |
49 | 49 |
50 // Start a pending navigation to a regular page. | 50 // Start a pending navigation to a regular page. |
51 GURL next_url("http://google.com/"); | 51 GURL next_url("http://google.com/"); |
52 controller->LoadURL(next_url, GURL(), PageTransition::LINK); | 52 controller->LoadURL(next_url, GURL(), PageTransition::LINK); |
53 | 53 |
54 // 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 |
55 // should reflect the old one (bookmark bar) until it has committed. | 55 // should reflect the old one (bookmark bar) until it has committed. |
56 EXPECT_TRUE(contents->ShouldDisplayURL()); | 56 EXPECT_TRUE(contents->ShouldDisplayURL()); |
57 EXPECT_TRUE(contents->ShouldDisplayFavIcon()); | 57 EXPECT_TRUE(contents->ShouldDisplayFavicon()); |
58 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); | 58 EXPECT_TRUE(contents->ShouldShowBookmarkBar()); |
59 EXPECT_FALSE(contents->FocusLocationBarByDefault()); | 59 EXPECT_FALSE(contents->FocusLocationBarByDefault()); |
60 | 60 |
61 // 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" |
62 // 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 |
63 // process transition, and our RVH pointer will be the "committed" one. | 63 // process transition, and our RVH pointer will be the "committed" one. |
64 // 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 |
65 // actually be pending, which is the point of this test. | 65 // actually be pending, which is the point of this test. |
66 if (contents->render_manager()->pending_render_view_host()) { | 66 if (contents->render_manager()->pending_render_view_host()) { |
67 static_cast<TestRenderViewHost*>( | 67 static_cast<TestRenderViewHost*>( |
68 contents->render_manager()->pending_render_view_host())->SendNavigate( | 68 contents->render_manager()->pending_render_view_host())->SendNavigate( |
69 page_id + 1, next_url); | 69 page_id + 1, next_url); |
70 } else { | 70 } else { |
71 static_cast<TestRenderViewHost*>( | 71 static_cast<TestRenderViewHost*>( |
72 contents->render_view_host())->SendNavigate(page_id + 1, next_url); | 72 contents->render_view_host())->SendNavigate(page_id + 1, next_url); |
73 } | 73 } |
74 | 74 |
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(WebUITest); | 85 DISALLOW_COPY_AND_ASSIGN(WebUITest); |
86 }; | 86 }; |
87 | 87 |
(...skipping 17 matching lines...) Expand all Loading... |
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(WebUITest, StandardToWebUI) { | 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()); |
131 | 131 |
132 // Commit the load, the state should be the same. | 132 // Commit the load, the state should be the same. |
133 rvh()->SendNavigate(1, std_url); | 133 rvh()->SendNavigate(1, std_url); |
134 EXPECT_TRUE(contents()->ShouldDisplayURL()); | 134 EXPECT_TRUE(contents()->ShouldDisplayURL()); |
135 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | 135 EXPECT_TRUE(contents()->ShouldDisplayFavicon()); |
136 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); | 136 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); |
137 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | 137 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); |
138 | 138 |
139 // Start a pending load for a WebUI. | 139 // Start a pending load for a WebUI. |
140 GURL new_tab_url(chrome::kChromeUINewTabURL); | 140 GURL new_tab_url(chrome::kChromeUINewTabURL); |
141 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); | 141 controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); |
142 EXPECT_FALSE(contents()->ShouldDisplayURL()); | 142 EXPECT_FALSE(contents()->ShouldDisplayURL()); |
143 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | 143 EXPECT_TRUE(contents()->ShouldDisplayFavicon()); |
144 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); | 144 EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); |
145 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | 145 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); |
146 | 146 |
147 // Committing Web UI is tested above. | 147 // Committing Web UI is tested above. |
148 } | 148 } |
149 | 149 |
150 class TabContentsForFocusTest : public TestTabContents { | 150 class TabContentsForFocusTest : public TestTabContents { |
151 public: | 151 public: |
152 TabContentsForFocusTest(Profile* profile, SiteInstance* instance) | 152 TabContentsForFocusTest(Profile* profile, SiteInstance* instance) |
153 : TestTabContents(profile, instance), focus_called_(0) { | 153 : TestTabContents(profile, instance), focus_called_(0) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |