Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" | 5 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import "ios/web/navigation/navigation_item_impl.h" | 9 #import "ios/web/navigation/navigation_item_impl.h" |
| 10 #import "ios/web/public/navigation_item.h" | 10 #import "ios/web/public/navigation_item.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #import "testing/gtest_mac.h" | 12 #import "testing/gtest_mac.h" |
| 13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 15 namespace web { | 19 namespace web { |
| 16 | 20 |
| 17 // Test fixture for WKBackForwardListItemHolder class. | 21 // Test fixture for WKBackForwardListItemHolder class. |
| 18 typedef PlatformTest WKBackForwardListItemHolderTest; | 22 typedef PlatformTest WKBackForwardListItemHolderTest; |
| 19 | 23 |
| 20 // Tests that FromNavigationItem returns the same holder for the same | 24 // Tests that FromNavigationItem returns the same holder for the same |
| 21 // NavigationItem. | 25 // NavigationItem. |
| 22 TEST_F(WKBackForwardListItemHolderTest, GetHolderFromNavigationItem) { | 26 TEST_F(WKBackForwardListItemHolderTest, GetHolderFromNavigationItem) { |
| 23 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); | 27 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); |
| 24 WKBackForwardListItemHolder* holder1 = | 28 WKBackForwardListItemHolder* holder1 = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 43 WKBackForwardListItemHolder::FromNavigationItem(item2.get()); | 47 WKBackForwardListItemHolder::FromNavigationItem(item2.get()); |
| 44 EXPECT_NE(holder1, holder2); | 48 EXPECT_NE(holder1, holder2); |
| 45 } | 49 } |
| 46 | 50 |
| 47 // Tests that acessors for the WKBackForwardListItem object work as | 51 // Tests that acessors for the WKBackForwardListItem object work as |
| 48 // expected. The test bellow uses NSObject instead of WKBackForwardListItem | 52 // expected. The test bellow uses NSObject instead of WKBackForwardListItem |
| 49 // because WKBackForwardListItem alloc/release is not designed to be called | 53 // because WKBackForwardListItem alloc/release is not designed to be called |
| 50 // directly and will crash. | 54 // directly and will crash. |
| 51 TEST_F(WKBackForwardListItemHolderTest, GetBackForwardListItemFromHolder) { | 55 TEST_F(WKBackForwardListItemHolderTest, GetBackForwardListItemFromHolder) { |
| 52 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); | 56 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); |
| 53 base::scoped_nsobject<NSObject> input([[NSObject alloc] init]); | 57 NSObject* input = [[NSObject alloc] init]; |
| 54 WKBackForwardListItemHolder* holder = | 58 WKBackForwardListItemHolder* holder = |
| 55 WKBackForwardListItemHolder::FromNavigationItem(item.get()); | 59 WKBackForwardListItemHolder::FromNavigationItem(item.get()); |
| 56 holder->set_back_forward_list_item( | 60 holder->set_back_forward_list_item( |
| 57 static_cast<WKBackForwardListItem*>(input.get())); | 61 static_cast<WKBackForwardListItem*>(input)); |
| 58 NSObject* result = holder->back_forward_list_item(); | 62 NSObject* result = holder->back_forward_list_item(); |
| 59 EXPECT_EQ(input, result); | 63 EXPECT_EQ(input, result); |
| 60 } | 64 } |
| 61 | 65 |
| 62 // Tests that acessors for navigation type work as expected. | 66 // Tests that acessors for navigation type work as expected. |
| 63 TEST_F(WKBackForwardListItemHolderTest, GetNavigationTypeFromHolder) { | 67 TEST_F(WKBackForwardListItemHolderTest, GetNavigationTypeFromHolder) { |
| 64 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); | 68 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); |
| 65 WKBackForwardListItemHolder* holder = | 69 WKBackForwardListItemHolder* holder = |
| 66 WKBackForwardListItemHolder::FromNavigationItem(item.get()); | 70 WKBackForwardListItemHolder::FromNavigationItem(item.get()); |
| 67 | 71 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 95 holder->set_navigation_type(type); | 99 holder->set_navigation_type(type); |
| 96 EXPECT_EQ(type, holder->navigation_type()); | 100 EXPECT_EQ(type, holder->navigation_type()); |
| 97 | 101 |
| 98 // Verify that setting 'WKNavigationTypeLinkActivated' means | 102 // Verify that setting 'WKNavigationTypeLinkActivated' means |
| 99 // |navigation_type| returns 'WKNavigationTypeLinkActivated' | 103 // |navigation_type| returns 'WKNavigationTypeLinkActivated' |
| 100 type = WKNavigationTypeLinkActivated; | 104 type = WKNavigationTypeLinkActivated; |
| 101 holder->set_navigation_type(type); | 105 holder->set_navigation_type(type); |
| 102 EXPECT_EQ(type, holder->navigation_type()); | 106 EXPECT_EQ(type, holder->navigation_type()); |
| 103 } | 107 } |
| 104 | 108 |
| 105 // Tests that |back_forward_list_item| returns nil if the internal | |
| 106 // WKBackForwardListItem was deallocated. The test bellow uses NSObject | |
| 107 // instead of WKBackForwardListItem because WKBackForwardListItem alloc/ | |
| 108 // release is not designed to be called directly and will crash. | |
| 109 TEST_F(WKBackForwardListItemHolderTest, GetNilBackForwardListItemFromHolder) { | |
|
Eugene But (OOO till 7-30)
2017/06/14 13:42:20
Sad.
marq (ping after 24h)
2017/06/14 14:19:02
Sad that the test was removed, or that it was ther
Eugene But (OOO till 7-30)
2017/06/14 14:25:53
That it was removed :)
I guess you think it was sa
| |
| 110 std::unique_ptr<web::NavigationItem> item(NavigationItem::Create()); | |
| 111 WKBackForwardListItemHolder* holder = | |
| 112 WKBackForwardListItemHolder::FromNavigationItem(item.get()); | |
| 113 | |
| 114 // Add a WKBackForwardListItem and verify that |back_forward_list_item| | |
| 115 // returns does not return nil. | |
| 116 base::scoped_nsobject<NSObject> input([[NSObject alloc] init]); | |
| 117 holder->set_back_forward_list_item( | |
| 118 static_cast<WKBackForwardListItem*>(input.get())); | |
| 119 NSObject* result = holder->back_forward_list_item(); | |
| 120 EXPECT_NE(nil, result); | |
| 121 | |
| 122 // Deallocate the WKBackForwardListItem and verify that | |
| 123 // |back_forward_list_item| returns nil. | |
| 124 input.reset(); | |
| 125 result = holder->back_forward_list_item(); | |
| 126 EXPECT_EQ(nil, result); | |
| 127 } | |
| 128 | |
| 129 } // namespace web | 109 } // namespace web |
| OLD | NEW |