Chromium Code Reviews| 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 <objc/runtime.h> | 5 #import <objc/runtime.h> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "ios/web/public/test/test_web_thread_bundle.h" | 32 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 33 #include "ios/web/public/web_thread.h" | 33 #include "ios/web/public/web_thread.h" |
| 34 #import "ios/web/web_state/ui/crw_web_controller.h" | 34 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 35 #import "ios/web/web_state/web_state_impl.h" | 35 #import "ios/web/web_state/web_state_impl.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "testing/gtest_mac.h" | 37 #include "testing/gtest_mac.h" |
| 38 #include "testing/platform_test.h" | 38 #include "testing/platform_test.h" |
| 39 #import "third_party/ocmock/OCMock/OCMock.h" | 39 #import "third_party/ocmock/OCMock/OCMock.h" |
| 40 #include "third_party/ocmock/gtest_support.h" | 40 #include "third_party/ocmock/gtest_support.h" |
| 41 | 41 |
| 42 using web::WebStateImpl; | |
| 43 | |
| 44 | |
| 45 @interface TabModel (VisibleForTesting) | 42 @interface TabModel (VisibleForTesting) |
| 46 - (SessionWindowIOS*)windowForSavingSession; | 43 - (SessionWindowIOS*)windowForSavingSession; |
| 47 @end | 44 @end |
| 48 | 45 |
| 49 // Defines a TabModelObserver for use in unittests. This class can be used to | 46 // Defines a TabModelObserver for use in unittests. This class can be used to |
| 50 // test if an observer method was called or not. | 47 // test if an observer method was called or not. |
| 51 @interface TabModelObserverPong : NSObject<TabModelObserver> { | 48 @interface TabModelObserverPong : NSObject<TabModelObserver> { |
| 52 // TODO(crbug.com/661989): Add tests for the other observer methods. | 49 // TODO(crbug.com/661989): Add tests for the other observer methods. |
| 53 BOOL tabMovedWasCalled_; | 50 BOOL tabMovedWasCalled_; |
| 54 } | 51 } |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1057 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); | 1054 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
| 1058 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); | 1055 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
| 1059 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); | 1056 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
| 1060 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]); | 1057 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]); |
| 1061 | 1058 |
| 1062 // TabModel asserts that there are no observer when it is deallocated, | 1059 // TabModel asserts that there are no observer when it is deallocated, |
| 1063 // so remove the observer before the end of the method. | 1060 // so remove the observer before the end of the method. |
| 1064 [tab_model_ removeObserver:tab_model_observer.get()]; | 1061 [tab_model_ removeObserver:tab_model_observer.get()]; |
| 1065 } | 1062 } |
| 1066 | 1063 |
| 1067 TEST_F(TabModelTest, SetParentModel) { | |
|
rohitrao (ping after 24h)
2017/04/03 17:49:35
Should we rewrite/fix this test instead of deletin
sdefresne
2017/04/04 13:47:56
Done. Also added a test that check a Tab is create
| |
| 1068 // Create a tab without a parent model and make sure it doesn't crash. Then | |
| 1069 // set its parent TabModel and make sure that works as well. | |
| 1070 base::scoped_nsobject<Tab> tab([[Tab alloc] | |
| 1071 initWithBrowserState:chrome_browser_state_.get() | |
| 1072 opener:nil | |
| 1073 openedByDOM:NO | |
| 1074 model:nil]); | |
| 1075 EXPECT_TRUE([tab parentTabModel] == nil); | |
| 1076 [tab_model_ insertTab:tab atIndex:0]; | |
| 1077 [tab setParentTabModel:tab_model_.get()]; | |
| 1078 EXPECT_FALSE([tab parentTabModel] == nil); | |
| 1079 [tab_model_ closeTabAtIndex:0]; | |
| 1080 } | |
| 1081 | |
| 1082 TEST_F(TabModelTest, PersistSelectionChange) { | 1064 TEST_F(TabModelTest, PersistSelectionChange) { |
| 1083 NSString* stashPath = | 1065 NSString* stashPath = |
| 1084 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value()); | 1066 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value()); |
| 1085 | 1067 |
| 1086 [tab_model_ insertTabWithURL:GURL(kURL1) | 1068 [tab_model_ insertTabWithURL:GURL(kURL1) |
| 1087 referrer:web::Referrer() | 1069 referrer:web::Referrer() |
| 1088 transition:ui::PAGE_TRANSITION_TYPED | 1070 transition:ui::PAGE_TRANSITION_TYPED |
| 1089 opener:nil | 1071 opener:nil |
| 1090 openedByDOM:NO | 1072 openedByDOM:NO |
| 1091 atIndex:[tab_model_ count] | 1073 atIndex:[tab_model_ count] |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]); | 1127 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]); |
| 1146 EXPECT_EQ([tab_model_ tabAtIndex:2], | 1128 EXPECT_EQ([tab_model_ tabAtIndex:2], |
| 1147 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]); | 1129 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]); |
| 1148 | 1130 |
| 1149 // Clean up. | 1131 // Clean up. |
| 1150 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath | 1132 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath |
| 1151 error:nullptr]); | 1133 error:nullptr]); |
| 1152 } | 1134 } |
| 1153 | 1135 |
| 1154 } // anonymous namespace | 1136 } // anonymous namespace |
| OLD | NEW |