Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: ios/chrome/browser/tabs/tab_model_unittest.mm

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix gn check Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h" 13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
14 #include "ios/chrome/browser/chrome_url_constants.h" 14 #include "ios/chrome/browser/chrome_url_constants.h"
15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" 15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
16 #include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h" 16 #include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h"
17 #import "ios/chrome/browser/sessions/session_window_ios.h" 17 #import "ios/chrome/browser/sessions/session_window_ios.h"
18 #import "ios/chrome/browser/sessions/test_session_service.h" 18 #import "ios/chrome/browser/sessions/test_session_service.h"
19 #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
19 #import "ios/chrome/browser/tabs/tab.h" 20 #import "ios/chrome/browser/tabs/tab.h"
21 #import "ios/chrome/browser/tabs/tab_helper_util.h"
20 #import "ios/chrome/browser/tabs/tab_model.h" 22 #import "ios/chrome/browser/tabs/tab_model.h"
21 #import "ios/chrome/browser/tabs/tab_model_observer.h" 23 #import "ios/chrome/browser/tabs/tab_model_observer.h"
22 #import "ios/chrome/browser/tabs/tab_private.h" 24 #import "ios/chrome/browser/tabs/tab_private.h"
23 #import "ios/chrome/browser/web/chrome_web_client.h" 25 #import "ios/chrome/browser/web/chrome_web_client.h"
24 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h" 26 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h"
27 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
25 #import "ios/web/navigation/crw_session_controller.h" 28 #import "ios/web/navigation/crw_session_controller.h"
26 #import "ios/web/navigation/navigation_manager_impl.h" 29 #import "ios/web/navigation/navigation_manager_impl.h"
27 #import "ios/web/public/crw_session_storage.h" 30 #import "ios/web/public/crw_session_storage.h"
28 #import "ios/web/public/navigation_manager.h" 31 #import "ios/web/public/navigation_manager.h"
29 #include "ios/web/public/referrer.h" 32 #include "ios/web/public/referrer.h"
30 #import "ios/web/public/serializable_user_data_manager.h" 33 #import "ios/web/public/serializable_user_data_manager.h"
31 #include "ios/web/public/test/scoped_testing_web_client.h" 34 #include "ios/web/public/test/scoped_testing_web_client.h"
32 #include "ios/web/public/test/test_web_thread_bundle.h" 35 #include "ios/web/public/test/test_web_thread_bundle.h"
33 #include "ios/web/public/web_thread.h" 36 #include "ios/web/public/web_thread.h"
34 #import "ios/web/web_state/ui/crw_web_controller.h" 37 #import "ios/web/web_state/ui/crw_web_controller.h"
35 #import "ios/web/web_state/web_state_impl.h" 38 #import "ios/web/web_state/web_state_impl.h"
36 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
37 #include "testing/gtest_mac.h" 40 #include "testing/gtest_mac.h"
38 #include "testing/platform_test.h" 41 #include "testing/platform_test.h"
39 #import "third_party/ocmock/OCMock/OCMock.h" 42 #import "third_party/ocmock/OCMock/OCMock.h"
40 #include "third_party/ocmock/gtest_support.h" 43 #include "third_party/ocmock/gtest_support.h"
41 44
42 using web::WebStateImpl;
43
44
45 @interface TabModel (VisibleForTesting) 45 @interface TabModel (VisibleForTesting)
46 - (SessionWindowIOS*)windowForSavingSession; 46 - (SessionWindowIOS*)windowForSavingSession;
47 @end 47 @end
48 48
49 // Defines a TabModelObserver for use in unittests. This class can be used to 49 // Defines a TabModelObserver for use in unittests. This class can be used to
50 // test if an observer method was called or not. 50 // test if an observer method was called or not.
51 @interface TabModelObserverPong : NSObject<TabModelObserver> { 51 @interface TabModelObserverPong : NSObject<TabModelObserver> {
52 // TODO(crbug.com/661989): Add tests for the other observer methods. 52 // TODO(crbug.com/661989): Add tests for the other observer methods.
53 BOOL tabMovedWasCalled_; 53 BOOL tabMovedWasCalled_;
54 } 54 }
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); 1057 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]);
1058 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); 1058 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]);
1059 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); 1059 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]);
1060 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]); 1060 EXPECT_FALSE([tab_model_observer tabMovedWasCalled]);
1061 1061
1062 // TabModel asserts that there are no observer when it is deallocated, 1062 // TabModel asserts that there are no observer when it is deallocated,
1063 // so remove the observer before the end of the method. 1063 // so remove the observer before the end of the method.
1064 [tab_model_ removeObserver:tab_model_observer.get()]; 1064 [tab_model_ removeObserver:tab_model_observer.get()];
1065 } 1065 }
1066 1066
1067 TEST_F(TabModelTest, SetParentModel) { 1067 TEST_F(TabModelTest, ParentTabModel) {
1068 // Create a tab without a parent model and make sure it doesn't crash. Then 1068 std::unique_ptr<web::WebState> web_state = web::WebState::Create(
1069 // set its parent TabModel and make sure that works as well. 1069 web::WebState::CreateParams(chrome_browser_state_.get()));
1070 base::scoped_nsobject<Tab> tab([[Tab alloc] 1070 AttachTabHelpers(web_state.get());
1071 initWithBrowserState:chrome_browser_state_.get() 1071
1072 opener:nil 1072 Tab* tab = LegacyTabHelper::GetTabForWebState(web_state.get());
1073 openedByDOM:NO 1073 EXPECT_NSEQ(nil, [tab parentTabModel]);
1074 model:nil]); 1074
1075 EXPECT_TRUE([tab parentTabModel] == nil); 1075 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state));
1076 [tab_model_ insertTab:tab atIndex:0]; 1076 EXPECT_NSEQ(tab_model_.get(), [tab parentTabModel]);
1077 [tab setParentTabModel:tab_model_.get()]; 1077 }
1078 EXPECT_FALSE([tab parentTabModel] == nil); 1078
1079 [tab_model_ closeTabAtIndex:0]; 1079 TEST_F(TabModelTest, TabCreatedOnInsertion) {
1080 std::unique_ptr<web::WebState> web_state = web::WebState::Create(
1081 web::WebState::CreateParams(chrome_browser_state_.get()));
1082
1083 EXPECT_NSEQ(nil, LegacyTabHelper::GetTabForWebState(web_state.get()));
1084
1085 web::WebState* web_state_ptr = web_state.get();
1086 [tab_model_ webStateList]->InsertWebState(0, std::move(web_state));
1087 EXPECT_NSNE(nil, LegacyTabHelper::GetTabForWebState(web_state_ptr));
1080 } 1088 }
1081 1089
1082 TEST_F(TabModelTest, PersistSelectionChange) { 1090 TEST_F(TabModelTest, PersistSelectionChange) {
1083 NSString* stashPath = 1091 NSString* stashPath =
1084 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value()); 1092 base::SysUTF8ToNSString(chrome_browser_state_->GetStatePath().value());
1085 1093
1086 [tab_model_ insertTabWithURL:GURL(kURL1) 1094 [tab_model_ insertTabWithURL:GURL(kURL1)
1087 referrer:web::Referrer() 1095 referrer:web::Referrer()
1088 transition:ui::PAGE_TRANSITION_TYPED 1096 transition:ui::PAGE_TRANSITION_TYPED
1089 opener:nil 1097 opener:nil
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]); 1153 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:2]]);
1146 EXPECT_EQ([tab_model_ tabAtIndex:2], 1154 EXPECT_EQ([tab_model_ tabAtIndex:2],
1147 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]); 1155 [tab_model_ openerOfTab:[tab_model_ tabAtIndex:0]]);
1148 1156
1149 // Clean up. 1157 // Clean up.
1150 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath 1158 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath
1151 error:nullptr]); 1159 error:nullptr]);
1152 } 1160 }
1153 1161
1154 } // anonymous namespace 1162 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model_observers_bridge.mm ('k') | ios/chrome/browser/tabs/tab_model_web_state_list_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698