OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
13 #include "components/bookmarks/test/bookmark_test_helpers.h" | 14 #include "components/bookmarks/test/bookmark_test_helpers.h" |
14 #include "components/toolbar/test_toolbar_model.h" | 15 #include "components/toolbar/test_toolbar_model.h" |
15 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 18 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" |
17 #import "ios/chrome/browser/tabs/tab.h" | 19 #import "ios/chrome/browser/tabs/tab.h" |
18 #import "ios/chrome/browser/tabs/tab_model.h" | 20 #import "ios/chrome/browser/tabs/tab_model.h" |
19 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" | 21 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" |
20 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" | 22 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" |
21 #import "ios/chrome/browser/xcallback_parameters.h" | 23 #import "ios/chrome/browser/xcallback_parameters.h" |
22 #import "ios/testing/ocmock_complex_type_helper.h" | 24 #import "ios/testing/ocmock_complex_type_helper.h" |
23 #include "ios/web/public/test/test_web_state.h" | 25 #import "ios/web/public/navigation_item.h" |
| 26 #import "ios/web/public/test/test_navigation_manager.h" |
| 27 #import "ios/web/public/test/test_web_state.h" |
24 #include "ios/web/public/test/test_web_thread.h" | 28 #include "ios/web/public/test/test_web_thread.h" |
25 #include "ios/web/public/test/test_web_thread_bundle.h" | 29 #include "ios/web/public/test/test_web_thread_bundle.h" |
26 #include "testing/gtest_mac.h" | 30 #include "testing/gtest_mac.h" |
27 #include "testing/platform_test.h" | 31 #include "testing/platform_test.h" |
28 #include "third_party/ocmock/gtest_support.h" | 32 #include "third_party/ocmock/gtest_support.h" |
29 #include "third_party/ocmock/ocmock_extensions.h" | 33 #include "third_party/ocmock/ocmock_extensions.h" |
30 | 34 |
31 @interface TMITestTabMock : OCMockComplexTypeHelper { | 35 @interface TMITestTabMock : OCMockComplexTypeHelper { |
32 GURL url_; | 36 GURL url_; |
33 web::WebState* web_state_; | 37 web::WebState* web_state_; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 bookmark_model->AddURL(bookmarks, bookmarks->child_count(), | 214 bookmark_model->AddURL(bookmarks, bookmarks->child_count(), |
211 base::UTF8ToUTF16(kWebUrl), GURL(kWebUrl)); | 215 base::UTF8ToUTF16(kWebUrl), GURL(kWebUrl)); |
212 EXPECT_TRUE(toolbarModel_->IsCurrentTabBookmarked()); | 216 EXPECT_TRUE(toolbarModel_->IsCurrentTabBookmarked()); |
213 | 217 |
214 // Remove the bookmark and verify the toolbar model indicates that the URL is | 218 // Remove the bookmark and verify the toolbar model indicates that the URL is |
215 // not bookmarked. | 219 // not bookmarked. |
216 bookmark_model->Remove(node); | 220 bookmark_model->Remove(node); |
217 EXPECT_FALSE(toolbarModel_->IsCurrentTabBookmarked()); | 221 EXPECT_FALSE(toolbarModel_->IsCurrentTabBookmarked()); |
218 } | 222 } |
219 | 223 |
| 224 TEST_F(ToolbarModelImplIOSTest, TestGetFormattedURL) { |
| 225 ToolbarModelImplIOSTestWebState web_state(chrome_browser_state_.get()); |
| 226 IOSSecurityStateTabHelper::CreateForWebState(&web_state); |
| 227 auto test_navigation_manager = base::MakeUnique<web::TestNavigationManager>(); |
| 228 auto visible_item = web::NavigationItem::Create(); |
| 229 test_navigation_manager->SetVisibleItem(visible_item.get()); |
| 230 web_state.SetNavigationManager(std::move(test_navigation_manager)); |
| 231 id tabMock = [[TMITestTabMock alloc] |
| 232 initWithRepresentedObject:[OCMockObject mockForClass:[Tab class]]]; |
| 233 OCMockObject* tabModelMock = static_cast<OCMockObject*>(tabModel_.get()); |
| 234 [[[tabModelMock stub] andReturn:tabMock] currentTab]; |
| 235 [static_cast<TMITestTabMock*>(tabMock) setWebState:&web_state]; |
| 236 |
| 237 size_t length = 0; |
| 238 const char no_scheme_url[] = "www.chromium.org"; |
| 239 const char http_url[] = "http://www.chromium.org"; |
| 240 const char https_url[] = "https://www.chromium.org"; |
| 241 const char chrome_url[] = "chrome://www.chromium.org"; |
| 242 const char offline_url[] = "chrome://offline/testid/page.html"; |
| 243 // Test that only http:// scheme is stripped out for online URL. |
| 244 visible_item->SetURL(GURL(http_url)); |
| 245 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 246 base::UTF8ToUTF16(no_scheme_url)); |
| 247 EXPECT_EQ(length, 0u); |
| 248 |
| 249 visible_item->SetURL(GURL(https_url)); |
| 250 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 251 base::UTF8ToUTF16(https_url)); |
| 252 EXPECT_EQ(length, 8u); |
| 253 |
| 254 visible_item->SetURL(GURL(chrome_url)); |
| 255 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 256 base::UTF8ToUTF16(chrome_url)); |
| 257 EXPECT_EQ(length, 9u); |
| 258 |
| 259 // Test that only http:// and https:// scheme are stripped out for offline |
| 260 // URL. |
| 261 visible_item->SetURL(GURL(offline_url)); |
| 262 visible_item->SetVirtualURL(GURL(http_url)); |
| 263 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 264 base::UTF8ToUTF16(no_scheme_url)); |
| 265 EXPECT_EQ(length, 0u); |
| 266 |
| 267 visible_item->SetVirtualURL(GURL(https_url)); |
| 268 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 269 base::UTF8ToUTF16(no_scheme_url)); |
| 270 EXPECT_EQ(length, 0u); |
| 271 |
| 272 visible_item->SetVirtualURL(GURL(chrome_url)); |
| 273 EXPECT_EQ(toolbarModel_->GetFormattedURL(&length), |
| 274 base::UTF8ToUTF16(chrome_url)); |
| 275 EXPECT_EQ(length, 9u); |
| 276 } |
| 277 |
220 } // namespace | 278 } // namespace |
OLD | NEW |