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/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 9 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
10 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/url_constants.h" |
11 | 13 |
12 typedef BrowserWithTestWindowTest ToolbarModelTest; | 14 class ToolbarModelTest : public BrowserWithTestWindowTest { |
| 15 public: |
| 16 ToolbarModelTest() {} |
13 | 17 |
| 18 protected: |
| 19 void NavigateAndCheckText(const std::string& url, |
| 20 const std::string& expected_text, |
| 21 bool should_display) { |
| 22 TabContents* contents = browser()->GetTabContentsAt(0); |
| 23 browser()->OpenURL(GURL(url), GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 24 |
| 25 // Check while loading. |
| 26 EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL()); |
| 27 EXPECT_EQ(ASCIIToUTF16(expected_text), |
| 28 browser()->toolbar_model()->GetText()); |
| 29 |
| 30 // Check after commit. |
| 31 CommitPendingLoad(&contents->controller()); |
| 32 EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL()); |
| 33 EXPECT_EQ(ASCIIToUTF16(expected_text), |
| 34 browser()->toolbar_model()->GetText()); |
| 35 } |
| 36 }; |
| 37 |
| 38 // Test that URLs are correctly shown or hidden both during navigation and |
| 39 // after commit. |
14 TEST_F(ToolbarModelTest, ShouldDisplayURL) { | 40 TEST_F(ToolbarModelTest, ShouldDisplayURL) { |
15 browser()->OpenURL(GURL("view-source:http://www.google.com"), | 41 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
16 GURL(), CURRENT_TAB, PageTransition::TYPED); | |
17 EXPECT_TRUE(browser()->toolbar_model()->ShouldDisplayURL()); | |
18 EXPECT_EQ(ASCIIToUTF16("view-source:www.google.com"), | |
19 browser()->toolbar_model()->GetText()); | |
20 | 42 |
21 browser()->OpenURL(GURL("view-source:chrome://newtab/"), | 43 NavigateAndCheckText("view-source:http://www.google.com", |
22 GURL(), CURRENT_TAB, PageTransition::TYPED); | 44 "view-source:www.google.com", true); |
23 EXPECT_TRUE(browser()->toolbar_model()->ShouldDisplayURL()); | 45 NavigateAndCheckText("view-source:chrome://newtab/", |
24 EXPECT_EQ(ASCIIToUTF16("view-source:chrome://newtab"), | 46 "view-source:chrome://newtab", true); |
25 browser()->toolbar_model()->GetText()); | 47 NavigateAndCheckText("chrome-extension://monkey/balls.html", "", false); |
26 | 48 NavigateAndCheckText("chrome://newtab/", "", false); |
27 browser()->OpenURL(GURL("chrome-extension://monkey/balls.html"), | 49 NavigateAndCheckText(chrome::kAboutBlankURL, chrome::kAboutBlankURL, true); |
28 GURL(), CURRENT_TAB, PageTransition::TYPED); | |
29 EXPECT_FALSE(browser()->toolbar_model()->ShouldDisplayURL()); | |
30 EXPECT_EQ(ASCIIToUTF16(""), browser()->toolbar_model()->GetText()); | |
31 | |
32 browser()->OpenURL(GURL("chrome://newtab/"), | |
33 GURL(), CURRENT_TAB, PageTransition::TYPED); | |
34 EXPECT_FALSE(browser()->toolbar_model()->ShouldDisplayURL()); | |
35 EXPECT_EQ(ASCIIToUTF16(""), browser()->toolbar_model()->GetText()); | |
36 | |
37 browser()->OpenURL(GURL("about:blank"), | |
38 GURL(), CURRENT_TAB, PageTransition::TYPED); | |
39 EXPECT_TRUE(browser()->toolbar_model()->ShouldDisplayURL()); | |
40 EXPECT_EQ(ASCIIToUTF16("about:blank"), | |
41 browser()->toolbar_model()->GetText()); | |
42 } | 50 } |
OLD | NEW |