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

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: test fix & removed include 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" 16 #import "ios/web/navigation/crw_session_controller.h"
17 #import "ios/web/public/crw_session_storage.h" 17 #import "ios/web/public/crw_session_storage.h"
18 #include "ios/web/public/test/test_web_thread_bundle.h" 18 #include "ios/web/public/test/test_web_thread_bundle.h"
19 #import "ios/web/public/web_state/web_state.h" 19 #import "ios/web/public/web_state/web_state.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/gtest_mac.h" 21 #include "testing/gtest_mac.h"
22 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
23 #import "third_party/ocmock/OCMock/OCMock.h" 23 #import "third_party/ocmock/OCMock/OCMock.h"
24 24
25 using web::WebStateImpl;
26
27 @interface SessionWindowIOS (Testing) 25 @interface SessionWindowIOS (Testing)
28 26
29 - (void)clearSessions; 27 - (void)clearSessions;
30 28
31 @end 29 @end
32 30
33 namespace { 31 namespace {
34 32
35 class SessionWindowIOSTest : public PlatformTest { 33 class SessionWindowIOSTest : public PlatformTest {
36 protected: 34 protected:
37 void SetUp() override { 35 void SetUp() override {
38 PlatformTest::SetUp(); 36 PlatformTest::SetUp();
39 TestChromeBrowserState::Builder test_cbs_builder; 37 TestChromeBrowserState::Builder test_cbs_builder;
40 chrome_browser_state_ = test_cbs_builder.Build(); 38 chrome_browser_state_ = test_cbs_builder.Build();
41 } 39 }
42 40
43 WebStateImpl* CreateWebState(BOOL openedByDOM) const { 41 std::unique_ptr<web::WebState> CreateWebState(
44 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get()); 42 bool created_with_opener) const {
45 webState->GetNavigationManagerImpl().InitializeSession(openedByDOM); 43 web::WebState::CreateParams params(chrome_browser_state_.get());
46 return webState; 44 params.created_with_opener = created_with_opener;
45 return web::WebState::Create(params);
47 } 46 }
48 47
49 web::TestWebThreadBundle thread_bundle_; 48 web::TestWebThreadBundle thread_bundle_;
50 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved 49 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved
51 // to be in the ios_web_unittests target. 50 // to be in the ios_web_unittests target.
52 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 51 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
53 }; 52 };
54 53
55 TEST_F(SessionWindowIOSTest, InitEmpty) { 54 TEST_F(SessionWindowIOSTest, InitEmpty) {
56 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 55 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
57 [[SessionWindowIOS alloc] init]); 56 [[SessionWindowIOS alloc] init]);
58 EXPECT_TRUE(sessionWindow.get() != nil); 57 EXPECT_TRUE(sessionWindow.get() != nil);
59 } 58 }
60 59
61 TEST_F(SessionWindowIOSTest, InitAddingSessions) { 60 TEST_F(SessionWindowIOSTest, InitAddingSessions) {
62 std::unique_ptr<WebStateImpl> webState1(CreateWebState(NO)); 61 std::unique_ptr<web::WebState> webState1 =
Eugene But (OOO till 7-30) 2017/03/18 00:33:29 nit: s/webState1/web_state_1 since you touching th
kkhorimoto 2017/03/20 22:39:20 Done.
63 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO)); 62 CreateWebState(false /*created_with_opener*/);
63 std::unique_ptr<web::WebState> webState2 =
64 CreateWebState(false /*created_with_opener*/);
64 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 65 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
65 [[SessionWindowIOS alloc] init]); 66 [[SessionWindowIOS alloc] init]);
66 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 67 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()];
67 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 68 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()];
68 [sessionWindow setSelectedIndex:1]; 69 [sessionWindow setSelectedIndex:1];
69 70
70 EXPECT_TRUE(sessionWindow.get() != nil); 71 EXPECT_TRUE(sessionWindow.get() != nil);
71 EXPECT_EQ(2U, sessionWindow.get().sessions.count); 72 EXPECT_EQ(2U, sessionWindow.get().sessions.count);
72 [sessionWindow clearSessions]; 73 [sessionWindow clearSessions];
73 EXPECT_EQ(0U, sessionWindow.get().sessions.count); 74 EXPECT_EQ(0U, sessionWindow.get().sessions.count);
74 } 75 }
75 76
76 TEST_F(SessionWindowIOSTest, CodingEncoding) { 77 TEST_F(SessionWindowIOSTest, CodingEncoding) {
77 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 78 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
78 [[SessionWindowIOS alloc] init]); 79 [[SessionWindowIOS alloc] init]);
79 80
80 std::unique_ptr<WebStateImpl> webState1(CreateWebState(YES)); 81 std::unique_ptr<web::WebState> webState1 =
81 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO)); 82 CreateWebState(true /*created_with_opener*/);
83 std::unique_ptr<web::WebState> webState2 =
84 CreateWebState(false /*created_with_opener*/);
82 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 85 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()];
83 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 86 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()];
84 87
85 [sessionWindow setSelectedIndex:1]; 88 [sessionWindow setSelectedIndex:1];
86 89
87 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow]; 90 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow];
88 EXPECT_TRUE(data != nil); 91 EXPECT_TRUE(data != nil);
89 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver( 92 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver(
90 [[SessionWindowUnarchiver alloc] 93 [[SessionWindowUnarchiver alloc]
91 initForReadingWithData:data 94 initForReadingWithData:data
92 browserState:chrome_browser_state_.get()]); 95 browserState:chrome_browser_state_.get()]);
93 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"]; 96 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"];
94 EXPECT_TRUE(unarchivedObj != nil); 97 EXPECT_TRUE(unarchivedObj != nil);
95 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex); 98 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex);
96 NSArray* sessions = unarchivedObj.sessions; 99 NSArray* sessions = unarchivedObj.sessions;
97 ASSERT_EQ(2U, sessions.count); 100 ASSERT_EQ(2U, sessions.count);
98 CRWSessionStorage* unarchivedSession1 = sessions[0]; 101 CRWSessionStorage* unarchivedSession1 = sessions[0];
99 EXPECT_TRUE(unarchivedSession1.openedByDOM); 102 EXPECT_TRUE(unarchivedSession1.hasOpener);
100 103
101 CRWSessionStorage* unarchivedSession2 = sessions[1]; 104 CRWSessionStorage* unarchivedSession2 = sessions[1];
102 EXPECT_FALSE(unarchivedSession2.openedByDOM); 105 EXPECT_FALSE(unarchivedSession2.hasOpener);
103 } 106 }
104 107
105 } // anonymous namespace 108 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698