summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/toolbar/toolbar_model_unittest.cc
blob: 5d321bc08101efcf0bbc1e9f625c599f3a6ea193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/toolbar/toolbar_model.h"

#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/common/url_constants.h"

class ToolbarModelTest : public BrowserWithTestWindowTest {
 public:
  ToolbarModelTest() {}

 protected:
  void NavigateAndCheckText(const std::string& url,
                            const std::string& expected_text,
                            bool should_display) {
    TabContents* contents = browser()->GetTabContentsAt(0);
    browser()->OpenURL(GURL(url), GURL(), CURRENT_TAB,
                       content::PAGE_TRANSITION_TYPED);

    // Check while loading.
    EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL());
    EXPECT_EQ(ASCIIToUTF16(expected_text),
              browser()->toolbar_model()->GetText());

    // Check after commit.
    CommitPendingLoad(&contents->GetController());
    EXPECT_EQ(should_display, browser()->toolbar_model()->ShouldDisplayURL());
    EXPECT_EQ(ASCIIToUTF16(expected_text),
              browser()->toolbar_model()->GetText());
  }
};

// Test that URLs are correctly shown or hidden both during navigation and
// after commit.
TEST_F(ToolbarModelTest, ShouldDisplayURL) {
  AddTab(browser(), GURL(chrome::kAboutBlankURL));

  NavigateAndCheckText("view-source:http://www.google.com",
                       "view-source:www.google.com", true);
  NavigateAndCheckText("view-source:chrome://newtab/",
                       "view-source:chrome://newtab", true);
  NavigateAndCheckText("chrome-extension://monkey/balls.html", "", false);
  NavigateAndCheckText("chrome://newtab/", "", false);
  NavigateAndCheckText(chrome::kAboutBlankURL, chrome::kAboutBlankURL, true);
}