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

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

Issue 2720613005: Refactor serialisation of openerId & openerNavigationIndex. (Closed)
Patch Set: Fix CRWSessionController's initializer comment. Created 3 years, 9 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
« no previous file with comments | « ios/chrome/browser/tabs/tab_model.mm ('k') | ios/chrome/browser/tabs/tab_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 17 #import "ios/chrome/browser/sessions/session_window.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/tab.h" 19 #import "ios/chrome/browser/tabs/tab.h"
20 #import "ios/chrome/browser/tabs/tab_model.h" 20 #import "ios/chrome/browser/tabs/tab_model.h"
21 #import "ios/chrome/browser/tabs/tab_model_observer.h" 21 #import "ios/chrome/browser/tabs/tab_model_observer.h"
22 #import "ios/chrome/browser/tabs/tab_private.h" 22 #import "ios/chrome/browser/tabs/tab_private.h"
23 #import "ios/chrome/browser/web/chrome_web_client.h" 23 #import "ios/chrome/browser/web/chrome_web_client.h"
24 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h" 24 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager .h"
25 #import "ios/web/navigation/crw_session_controller.h" 25 #import "ios/web/navigation/crw_session_controller.h"
26 #import "ios/web/navigation/navigation_manager_impl.h" 26 #import "ios/web/navigation/navigation_manager_impl.h"
27 #import "ios/web/public/navigation_manager.h" 27 #import "ios/web/public/navigation_manager.h"
28 #include "ios/web/public/referrer.h" 28 #include "ios/web/public/referrer.h"
29 #import "ios/web/public/serializable_user_data_manager.h"
29 #include "ios/web/public/test/scoped_testing_web_client.h" 30 #include "ios/web/public/test/scoped_testing_web_client.h"
30 #include "ios/web/public/test/test_web_thread_bundle.h" 31 #include "ios/web/public/test/test_web_thread_bundle.h"
31 #include "ios/web/public/web_thread.h" 32 #include "ios/web/public/web_thread.h"
32 #import "ios/web/web_state/ui/crw_web_controller.h" 33 #import "ios/web/web_state/ui/crw_web_controller.h"
33 #import "ios/web/web_state/web_state_impl.h" 34 #import "ios/web/web_state/web_state_impl.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 #include "testing/gtest_mac.h" 36 #include "testing/gtest_mac.h"
36 #include "testing/platform_test.h" 37 #include "testing/platform_test.h"
37 #import "third_party/ocmock/OCMock/OCMock.h" 38 #import "third_party/ocmock/OCMock/OCMock.h"
38 #include "third_party/ocmock/gtest_support.h" 39 #include "third_party/ocmock/gtest_support.h"
(...skipping 24 matching lines...) Expand all
63 64
64 - (instancetype)initWithWindowName:(NSString*)windowName 65 - (instancetype)initWithWindowName:(NSString*)windowName
65 lastVisitedTimestamp:(double)lastVisitedTimestamp 66 lastVisitedTimestamp:(double)lastVisitedTimestamp
66 browserState:(ios::ChromeBrowserState*)browserState 67 browserState:(ios::ChromeBrowserState*)browserState
67 tabModel:(TabModel*)tabModel { 68 tabModel:(TabModel*)tabModel {
68 id webControllerMock = 69 id webControllerMock =
69 [OCMockObject niceMockForClass:[CRWWebController class]]; 70 [OCMockObject niceMockForClass:[CRWWebController class]];
70 71
71 auto webStateImpl = base::MakeUnique<WebStateImpl>(browserState); 72 auto webStateImpl = base::MakeUnique<WebStateImpl>(browserState);
72 webStateImpl->SetWebController(webControllerMock); 73 webStateImpl->SetWebController(webControllerMock);
73 webStateImpl->GetNavigationManagerImpl().InitializeSession(windowName, 74 webStateImpl->GetNavigationManagerImpl().InitializeSession(windowName, NO);
74 @"opener", NO, -1);
75 [webStateImpl->GetNavigationManagerImpl().GetSessionController() 75 [webStateImpl->GetNavigationManagerImpl().GetSessionController()
76 setLastVisitedTimestamp:lastVisitedTimestamp]; 76 setLastVisitedTimestamp:lastVisitedTimestamp];
77 77
78 WebStateImpl* webStateImplPtr = webStateImpl.get(); 78 WebStateImpl* webStateImplPtr = webStateImpl.get();
79 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(webStateImplPtr)] 79 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(webStateImplPtr)]
80 webStateImpl]; 80 webStateImpl];
81 BOOL yes = YES; 81 BOOL yes = YES;
82 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(yes)] isViewAlive]; 82 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(yes)] isViewAlive];
83 83
84 if ((self = [super initWithWebState:std::move(webStateImpl) 84 if ((self = [super initWithWebState:std::move(webStateImpl)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ~TabModelTest() override { 154 ~TabModelTest() override {
155 [tab_model_ removeObserver:tab_model_observer_]; 155 [tab_model_ removeObserver:tab_model_observer_];
156 [tab_model_ browserStateDestroyed]; 156 [tab_model_ browserStateDestroyed];
157 } 157 }
158 158
159 protected: 159 protected:
160 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName, 160 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName,
161 NSString* opener, 161 NSString* opener,
162 NSInteger index) { 162 NSInteger index) {
163 auto webState = base::MakeUnique<WebStateImpl>(chrome_browser_state_.get()); 163 auto webState = base::MakeUnique<WebStateImpl>(chrome_browser_state_.get());
164 webState->GetNavigationManagerImpl().InitializeSession(windowName, opener, 164 webState->GetNavigationManagerImpl().InitializeSession(windowName, NO);
165 NO, index); 165 if ([opener length] != 0) {
166 // Duplicate code from Tab initializer. Will be removed once the code
167 // is rewritten to remove the use of internal ios/web/ API (see issue
168 // http://crbug.com/620465 for progress).
169 web::SerializableUserDataManager* userDataManager =
170 web::SerializableUserDataManager::FromWebState(webState.get());
171 userDataManager->AddSerializableData(opener, @"OpenerID");
172 userDataManager->AddSerializableData(@(index), @"OpenerNavigationIndex");
173 }
166 return webState; 174 return webState;
167 } 175 }
168 176
169 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName) { 177 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName) {
170 return CreateWebState(windowName, @"", -1); 178 return CreateWebState(windowName, @"", -1);
171 } 179 }
172 180
173 std::unique_ptr<WebStateImpl> CreateChildWebState(Tab* parent) { 181 std::unique_ptr<WebStateImpl> CreateChildWebState(Tab* parent) {
174 return CreateWebState([parent windowName], parent.tabId, -1); 182 return CreateWebState([parent windowName], parent.tabId, -1);
175 } 183 }
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 // Restoring TabModel session sends asynchronous tasks to IO thread, wait 900 // Restoring TabModel session sends asynchronous tasks to IO thread, wait
893 // for them to complete after destroying the TabModel. 901 // for them to complete after destroying the TabModel.
894 base::RunLoop().RunUntilIdle(); 902 base::RunLoop().RunUntilIdle();
895 903
896 // Clean up. 904 // Clean up.
897 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath 905 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath
898 error:nullptr]); 906 error:nullptr]);
899 } 907 }
900 908
901 } // anonymous namespace 909 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_model.mm ('k') | ios/chrome/browser/tabs/tab_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698