OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/toolbar/toolbar_model.h" | 5 #include "components/toolbar/toolbar_model.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/test/base/browser_with_test_window_test.h" | 16 #include "chrome/test/base/browser_with_test_window_test.h" |
17 #include "components/toolbar/toolbar_model.h" | 17 #include "components/toolbar/toolbar_model.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/ssl_status.h" | 19 #include "content/public/browser/ssl_status.h" |
20 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
22 #include "ui/gfx/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
23 | 23 |
| 24 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 25 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/common/test_util.h" |
| 27 #endif |
| 28 |
24 // Test data ------------------------------------------------------------------ | 29 // Test data ------------------------------------------------------------------ |
25 | 30 |
26 namespace { | 31 namespace { |
27 | 32 |
28 struct TestItem { | 33 struct TestItem { |
29 GURL url; | 34 GURL url; |
30 base::string16 expected_text; | 35 base::string16 expected_text; |
31 } test_items[] = { | 36 } test_items[] = { |
32 { | 37 { |
33 GURL("view-source:http://www.google.com"), | 38 GURL("view-source:http://www.google.com"), |
34 base::ASCIIToUTF16("view-source:www.google.com") | 39 base::ASCIIToUTF16("view-source:www.google.com"), |
35 }, | 40 }, |
36 { | 41 { |
37 GURL("view-source:chrome://newtab/"), | 42 GURL("view-source:chrome://newtab/"), |
38 base::ASCIIToUTF16("view-source:chrome://newtab") | 43 base::ASCIIToUTF16("view-source:chrome://newtab"), |
39 }, | 44 }, |
40 { | 45 { |
41 GURL("chrome-extension://foo/bar.html"), | 46 GURL("chrome-extension://fooooooooooooooooooooooooooooooo/bar.html"), |
42 base::ASCIIToUTF16("chrome-extension://foo/bar.html") | 47 base::ASCIIToUTF16( |
43 }, | 48 "chrome-extension://fooooooooooooooooooooooooooooooo/bar.html"), |
44 { | 49 }, |
45 GURL(url::kAboutBlankURL), | 50 { |
46 base::ASCIIToUTF16(url::kAboutBlankURL) | 51 GURL(url::kAboutBlankURL), base::ASCIIToUTF16(url::kAboutBlankURL), |
47 }, | 52 }, |
48 { | 53 { |
49 GURL("http://searchurl/?q=tractor+supply"), | 54 GURL("http://searchurl/?q=tractor+supply"), |
50 base::ASCIIToUTF16("searchurl/?q=tractor+supply") | 55 base::ASCIIToUTF16("searchurl/?q=tractor+supply"), |
51 }, | 56 }, |
52 { | 57 { |
53 GURL("http://google.com/search?q=tractor+supply&espv=1"), | 58 GURL("http://google.com/search?q=tractor+supply&espv=1"), |
54 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1") | 59 base::ASCIIToUTF16("google.com/search?q=tractor+supply&espv=1"), |
55 }, | 60 }, |
56 { | 61 { |
57 GURL("https://google.ca/search?q=tractor+supply"), | 62 GURL("https://google.ca/search?q=tractor+supply"), |
58 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply") | 63 base::ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
59 }, | 64 }, |
60 }; | 65 }; |
61 | 66 |
62 } // namespace | 67 } // namespace |
63 | 68 |
64 | 69 |
65 // ToolbarModelTest ----------------------------------------------------------- | 70 // ToolbarModelTest ----------------------------------------------------------- |
66 | 71 |
67 class ToolbarModelTest : public BrowserWithTestWindowTest { | 72 class ToolbarModelTest : public BrowserWithTestWindowTest { |
68 public: | 73 public: |
69 ToolbarModelTest(); | 74 ToolbarModelTest(); |
(...skipping 14 matching lines...) Expand all Loading... |
84 ToolbarModelTest::ToolbarModelTest() { | 89 ToolbarModelTest::ToolbarModelTest() { |
85 } | 90 } |
86 | 91 |
87 ToolbarModelTest::~ToolbarModelTest() { | 92 ToolbarModelTest::~ToolbarModelTest() { |
88 } | 93 } |
89 | 94 |
90 void ToolbarModelTest::SetUp() { | 95 void ToolbarModelTest::SetUp() { |
91 BrowserWithTestWindowTest::SetUp(); | 96 BrowserWithTestWindowTest::SetUp(); |
92 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 97 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
93 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); | 98 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); |
| 99 |
| 100 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 101 // Install a fake extension so that the ID in the chrome-extension test URL is |
| 102 // valid. Invalid extension URLs may result in error pages (if blocked by |
| 103 // ExtensionNavigationThrottle), which this test doesn't wish to exercise. |
| 104 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile())->AddEnabled( |
| 105 extensions::test_util::CreateEmptyExtension( |
| 106 "fooooooooooooooooooooooooooooooo"))); |
| 107 #endif |
94 } | 108 } |
95 | 109 |
96 void ToolbarModelTest::NavigateAndCheckText( | 110 void ToolbarModelTest::NavigateAndCheckText( |
97 const GURL& url, | 111 const GURL& url, |
98 const base::string16& expected_text) { | 112 const base::string16& expected_text) { |
99 // Check while loading. | 113 // Check while loading. |
100 content::NavigationController* controller = | 114 content::NavigationController* controller = |
101 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); | 115 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
102 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 116 controller->LoadURL(url, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
103 std::string()); | 117 std::string()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 159 } |
146 } | 160 } |
147 | 161 |
148 TEST_F(ToolbarModelTest, ShouldElideLongURLs) { | 162 TEST_F(ToolbarModelTest, ShouldElideLongURLs) { |
149 AddTab(browser(), GURL(url::kAboutBlankURL)); | 163 AddTab(browser(), GURL(url::kAboutBlankURL)); |
150 const std::string long_text(content::kMaxURLDisplayChars + 1024, '0'); | 164 const std::string long_text(content::kMaxURLDisplayChars + 1024, '0'); |
151 NavigateAndCheckElided( | 165 NavigateAndCheckElided( |
152 GURL(std::string("https://www.foo.com/?") + long_text)); | 166 GURL(std::string("https://www.foo.com/?") + long_text)); |
153 NavigateAndCheckElided(GURL(std::string("data:abc") + long_text)); | 167 NavigateAndCheckElided(GURL(std::string("data:abc") + long_text)); |
154 } | 168 } |
OLD | NEW |