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

Side by Side Diff: ios/chrome/browser/sessions/session_window_unittest.mm

Issue 2755823002: Moved |openedByDOM| to WebState's CreateParams and public interface. (Closed)
Patch Set: . 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
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 "ios/chrome/browser/sessions/session_window.h" 5 #import "ios/chrome/browser/sessions/session_window.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
15 #import "ios/chrome/browser/sessions/session_service.h" 15 #import "ios/chrome/browser/sessions/session_service.h"
16 #import "ios/web/navigation/crw_session_controller.h"
17 #import "ios/web/public/crw_session_storage.h" 16 #import "ios/web/public/crw_session_storage.h"
18 #include "ios/web/public/test/test_web_thread_bundle.h" 17 #include "ios/web/public/test/test_web_thread_bundle.h"
19 #import "ios/web/public/web_state/web_state.h" 18 #import "ios/web/public/web_state/web_state.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/gtest_mac.h" 20 #include "testing/gtest_mac.h"
22 #include "testing/platform_test.h" 21 #include "testing/platform_test.h"
23 #import "third_party/ocmock/OCMock/OCMock.h" 22 #import "third_party/ocmock/OCMock/OCMock.h"
24 23
25 using web::WebStateImpl;
26
27 @interface SessionWindowIOS (Testing) 24 @interface SessionWindowIOS (Testing)
28 25
29 - (void)clearSessions; 26 - (void)clearSessions;
30 27
31 @end 28 @end
32 29
33 namespace { 30 namespace {
34 31
35 class SessionWindowIOSTest : public PlatformTest { 32 class SessionWindowIOSTest : public PlatformTest {
36 protected: 33 protected:
37 void SetUp() override { 34 void SetUp() override {
38 PlatformTest::SetUp(); 35 PlatformTest::SetUp();
39 TestChromeBrowserState::Builder test_cbs_builder; 36 TestChromeBrowserState::Builder test_cbs_builder;
40 chrome_browser_state_ = test_cbs_builder.Build(); 37 chrome_browser_state_ = test_cbs_builder.Build();
41 } 38 }
42 39
43 WebStateImpl* CreateWebState(BOOL openedByDOM) const { 40 std::unique_ptr<web::WebState> CreateWebState(
44 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get()); 41 bool created_with_opener) const {
45 webState->GetNavigationManagerImpl().InitializeSession(openedByDOM); 42 web::WebState::CreateParams params(chrome_browser_state_.get());
46 return webState; 43 params.created_with_opener = created_with_opener;
44 return web::WebState::Create(params);
47 } 45 }
48 46
49 web::TestWebThreadBundle thread_bundle_; 47 web::TestWebThreadBundle thread_bundle_;
50 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved 48 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved
51 // to be in the ios_web_unittests target. 49 // to be in the ios_web_unittests target.
52 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 50 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
53 }; 51 };
54 52
55 TEST_F(SessionWindowIOSTest, InitEmpty) { 53 TEST_F(SessionWindowIOSTest, InitEmpty) {
56 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 54 base::scoped_nsobject<SessionWindowIOS> session_window(
57 [[SessionWindowIOS alloc] init]); 55 [[SessionWindowIOS alloc] init]);
58 EXPECT_TRUE(sessionWindow.get() != nil); 56 EXPECT_TRUE(session_window.get() != nil);
59 } 57 }
60 58
61 TEST_F(SessionWindowIOSTest, InitAddingSessions) { 59 TEST_F(SessionWindowIOSTest, InitAddingSessions) {
62 std::unique_ptr<WebStateImpl> webState1(CreateWebState(NO)); 60 std::unique_ptr<web::WebState> web_state_1 =
63 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO)); 61 CreateWebState(false /*created_with_opener*/);
64 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 62 std::unique_ptr<web::WebState> web_state_2 =
63 CreateWebState(false /*created_with_opener*/);
64 base::scoped_nsobject<SessionWindowIOS> session_window(
65 [[SessionWindowIOS alloc] init]); 65 [[SessionWindowIOS alloc] init]);
66 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 66 [session_window
67 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 67 addSerializedSessionStorage:web_state_1->BuildSessionStorage()];
68 [sessionWindow setSelectedIndex:1]; 68 [session_window
69 addSerializedSessionStorage:web_state_2->BuildSessionStorage()];
70 [session_window setSelectedIndex:1];
69 71
70 EXPECT_TRUE(sessionWindow.get() != nil); 72 EXPECT_TRUE(session_window.get() != nil);
71 EXPECT_EQ(2U, sessionWindow.get().sessions.count); 73 EXPECT_EQ(2U, session_window.get().sessions.count);
72 [sessionWindow clearSessions]; 74 [session_window clearSessions];
73 EXPECT_EQ(0U, sessionWindow.get().sessions.count); 75 EXPECT_EQ(0U, session_window.get().sessions.count);
74 } 76 }
75 77
76 TEST_F(SessionWindowIOSTest, CodingEncoding) { 78 TEST_F(SessionWindowIOSTest, CodingEncoding) {
77 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 79 base::scoped_nsobject<SessionWindowIOS> session_window(
78 [[SessionWindowIOS alloc] init]); 80 [[SessionWindowIOS alloc] init]);
79 81
80 std::unique_ptr<WebStateImpl> webState1(CreateWebState(YES)); 82 std::unique_ptr<web::WebState> web_state_1 =
81 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO)); 83 CreateWebState(true /*created_with_opener*/);
82 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 84 std::unique_ptr<web::WebState> web_state_2 =
83 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 85 CreateWebState(false /*created_with_opener*/);
86 [session_window
87 addSerializedSessionStorage:web_state_1->BuildSessionStorage()];
88 [session_window
89 addSerializedSessionStorage:web_state_2->BuildSessionStorage()];
84 90
85 [sessionWindow setSelectedIndex:1]; 91 [session_window setSelectedIndex:1];
86 92
87 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow]; 93 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:session_window];
88 EXPECT_TRUE(data != nil); 94 EXPECT_TRUE(data != nil);
89 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver( 95 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver(
90 [[SessionWindowUnarchiver alloc] 96 [[SessionWindowUnarchiver alloc]
91 initForReadingWithData:data 97 initForReadingWithData:data
92 browserState:chrome_browser_state_.get()]); 98 browserState:chrome_browser_state_.get()]);
93 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"]; 99 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"];
94 EXPECT_TRUE(unarchivedObj != nil); 100 EXPECT_TRUE(unarchivedObj != nil);
95 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex); 101 EXPECT_EQ(unarchivedObj.selectedIndex, session_window.get().selectedIndex);
96 NSArray* sessions = unarchivedObj.sessions; 102 NSArray* sessions = unarchivedObj.sessions;
97 ASSERT_EQ(2U, sessions.count); 103 ASSERT_EQ(2U, sessions.count);
98 CRWSessionStorage* unarchivedSession1 = sessions[0]; 104 CRWSessionStorage* unarchivedSession1 = sessions[0];
99 EXPECT_TRUE(unarchivedSession1.openedByDOM); 105 EXPECT_TRUE(unarchivedSession1.hasOpener);
100 106
101 CRWSessionStorage* unarchivedSession2 = sessions[1]; 107 CRWSessionStorage* unarchivedSession2 = sessions[1];
102 EXPECT_FALSE(unarchivedSession2.openedByDOM); 108 EXPECT_FALSE(unarchivedSession2.hasOpener);
103 } 109 }
104 110
105 } // anonymous namespace 111 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/sessions/session_window.mm ('k') | ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698