Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/dom_ui/new_tab_ui.h" | |
| 6 #include "chrome/browser/renderer_host/test_render_view_host.h" | |
| 7 #include "chrome/common/url_constants.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 class DOMUITest : public RenderViewHostTestHarness { | |
| 11 public: | |
| 12 DOMUITest() {} | |
| 13 | |
| 14 private: | |
| 15 DISALLOW_COPY_AND_ASSIGN(DOMUITest); | |
| 16 }; | |
| 17 | |
| 18 // Tests that the New Tab Page flags are correctly set and propogated by | |
| 19 // WebContents when we first navigate do a DOM UI page, then to a standard | |
|
jcampan
2009/03/25 17:01:43
nit: typo "navigate do a DOM UI page" -> "to a DOM
| |
| 20 // non-DOM-UI page. | |
| 21 TEST_F(DOMUITest, DOMUIToStandard) { | |
| 22 // Start a pending load. | |
| 23 GURL new_tab_url(chrome::kChromeUINewTabURL); | |
| 24 controller()->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | |
| 25 | |
| 26 // The navigation entry should be pending with no committed entry. | |
| 27 ASSERT_TRUE(controller()->GetPendingEntry()); | |
| 28 ASSERT_FALSE(controller()->GetLastCommittedEntry()); | |
| 29 | |
| 30 // Check the things the pending DOM UI should have set. | |
| 31 EXPECT_FALSE(contents()->ShouldDisplayURL()); | |
| 32 EXPECT_FALSE(contents()->ShouldDisplayFavIcon()); | |
| 33 EXPECT_TRUE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 34 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | |
| 35 | |
| 36 // Now commit the load. | |
| 37 rvh()->SendNavigate(1, new_tab_url); | |
| 38 | |
| 39 // The same flags should be set as before now that the load has committed. | |
| 40 // Note that the location bar isn't focused now. Once the load commits, we | |
| 41 // don't care about this flag, so this value is OK. | |
| 42 EXPECT_FALSE(contents()->ShouldDisplayURL()); | |
| 43 EXPECT_FALSE(contents()->ShouldDisplayFavIcon()); | |
| 44 EXPECT_TRUE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 45 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 46 | |
| 47 // Start a pending navigation to a regular page. | |
| 48 GURL next_url("http://google.com/"); | |
| 49 controller()->LoadURL(next_url, GURL(), PageTransition::LINK); | |
| 50 | |
| 51 // Check the flags. Some should reflect the new page (URL, title), some should | |
| 52 // reflect the old one (bookmark bar) until it has committed. | |
| 53 EXPECT_TRUE(contents()->ShouldDisplayURL()); | |
| 54 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | |
| 55 EXPECT_TRUE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 56 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 57 | |
| 58 // Commit the regular page load. Note that we must send it to the "pending" | |
| 59 // RenderViewHost, since this transition will also cause a process transition, | |
| 60 // and our RVH pointer will be the "committed" one. | |
| 61 static_cast<TestRenderViewHost*>(contents()->render_manager()->pending_render_ view_host())->SendNavigate(2, next_url); | |
|
jcampan
2009/03/25 17:01:43
Line is more than 80 chars
| |
| 62 | |
| 63 // The state should now reflect a regular page. | |
| 64 EXPECT_TRUE(contents()->ShouldDisplayURL()); | |
| 65 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | |
| 66 EXPECT_FALSE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 67 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 68 } | |
| 69 | |
| 70 TEST_F(DOMUITest, DOMUIToDOMUI) { | |
| 71 // Do a load (this state is tested above). | |
| 72 GURL new_tab_url(chrome::kChromeUINewTabURL); | |
| 73 controller()->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | |
| 74 rvh()->SendNavigate(1, new_tab_url); | |
| 75 | |
| 76 // Start another pending load of the new tab page. | |
| 77 controller()->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | |
| 78 rvh()->SendNavigate(2, new_tab_url); | |
| 79 | |
| 80 // The flags should be the same as the non-pending state. | |
| 81 EXPECT_FALSE(contents()->ShouldDisplayURL()); | |
| 82 EXPECT_FALSE(contents()->ShouldDisplayFavIcon()); | |
| 83 EXPECT_TRUE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 84 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 85 } | |
| 86 | |
| 87 TEST_F(DOMUITest, StandardToDOMUI) { | |
| 88 // Start a pending navigation to a regular page. | |
| 89 GURL std_url("http://google.com/"); | |
| 90 controller()->LoadURL(std_url, GURL(), PageTransition::LINK); | |
| 91 | |
| 92 // The state should now reflect the default. | |
| 93 EXPECT_TRUE(contents()->ShouldDisplayURL()); | |
| 94 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | |
| 95 EXPECT_FALSE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 96 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 97 | |
| 98 // Commit the load, the state should be the same. | |
| 99 rvh()->SendNavigate(1, std_url); | |
| 100 EXPECT_TRUE(contents()->ShouldDisplayURL()); | |
| 101 EXPECT_TRUE(contents()->ShouldDisplayFavIcon()); | |
| 102 EXPECT_FALSE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 103 EXPECT_FALSE(contents()->FocusLocationBarByDefault()); | |
| 104 | |
| 105 // Start a pending load for a DOMUI. | |
| 106 GURL new_tab_url(chrome::kChromeUINewTabURL); | |
| 107 controller()->LoadURL(new_tab_url, GURL(), PageTransition::LINK); | |
| 108 EXPECT_FALSE(contents()->ShouldDisplayURL()); | |
| 109 EXPECT_FALSE(contents()->ShouldDisplayFavIcon()); | |
| 110 EXPECT_FALSE(contents()->IsBookmarkBarAlwaysVisible()); | |
| 111 EXPECT_TRUE(contents()->FocusLocationBarByDefault()); | |
| 112 | |
| 113 // Committing DOM UI is tested above. | |
| 114 } | |
| OLD | NEW |