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

Side by Side Diff: ios/clean/chrome/browser/ui/overlays/overlay_queue_unittest.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: Cancel overlays on queue deallocation Created 3 years, 6 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/clean/chrome/browser/ui/overlays/overlay_queue.h"
6
7 #if !defined(__has_feature) || !__has_feature(objc_arc)
8 #error "This file requires ARC support."
9 #endif
10
11 #import "base/mac/scoped_nsobject.h"
12 #include "base/memory/ptr_util.h"
13 #import "ios/clean/chrome/browser/ui/commands/overlay_commands.h"
14 #import "ios/web/public/test/fakes/test_web_state.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/gtest_mac.h"
17 #include "testing/platform_test.h"
18
19 // Test overlay coordinator subclass.
20 @interface TestOverlayCoordinator : OverlayCoordinator
21 // Whether the completion block has been cancelled.
22 @property(nonatomic, readonly) BOOL completionWasCancelled;
23 // The coordinator on which this has been started.
24 @property(nonatomic, readonly) BrowserCoordinator* webCoordinator;
25 @end
26
27 @implementation TestOverlayCoordinator
28 @synthesize completionWasCancelled = _completionWasCancelled;
29 @synthesize webCoordinator = _webCoordinator;
30
31 - (void)cancelWebKitCompletion {
32 _completionWasCancelled = YES;
33 }
34
35 - (void)startOverlayingWebCoordinator:(BrowserCoordinator*)webCoordinator {
36 _webCoordinator = webCoordinator;
37 }
38
39 @end
40
41 // Test overlay scheduler subclass.
42 @interface TestOverlayScheduler : NSObject<OverlaySchedulerCommands>
43 @property(nonatomic, readonly) web::WebState* nextWebState;
44 @end
45
46 @implementation TestOverlayScheduler
47 @synthesize nextWebState = _nextWebState;
48
49 - (void)scheduleOverlayForWebState:(web::WebState*)webState {
50 _nextWebState = webState;
51 }
52 - (void)overlayWasStoppedForWebState:(web::WebState*)webState {
53 }
54 - (void)cancelOverlaysForWebState:(web::WebState*)webState {
55 }
56 @end
57
58 class OverlayQueueTest : public PlatformTest {
59 public:
60 OverlayQueueTest()
61 : PlatformTest(), scheduler_([[TestOverlayScheduler alloc] init]) {
62 OverlayQueue::CreateForWebState(&web_state_, scheduler_);
63 }
64
65 web::WebState* web_state() { return &web_state_; }
66
67 OverlayQueue* queue() { return OverlayQueue::FromWebState(&web_state_); }
68
69 TestOverlayScheduler* scheduler() { return scheduler_; }
70
71 private:
72 web::TestWebState web_state_;
73 base::scoped_nsobject<TestOverlayScheduler> scheduler_;
74 };
75
76 // Tests that adding an overlay to the queue updates state accordingly and
77 // dispatches a |-scheduleOverlayForWebState:| command.
78 TEST_F(OverlayQueueTest, AddOverlay) {
79 TestOverlayCoordinator* overlay =
80 [[TestOverlayCoordinator alloc] initWithWebState:web_state()];
81 queue()->AddOverlay(overlay);
82 EXPECT_TRUE(queue()->HasQueuedOverlays());
83 EXPECT_FALSE(queue()->IsShowingOverlay());
84 EXPECT_EQ(web_state(), scheduler().nextWebState);
85 }
86
87 // Tests that starting an overlay updates state and starts the queued overlay.
88 TEST_F(OverlayQueueTest, StartOverlay) {
89 TestOverlayCoordinator* overlay =
90 [[TestOverlayCoordinator alloc] initWithWebState:web_state()];
91 queue()->AddOverlay(overlay);
92 BrowserCoordinator* web_coordinator = [[BrowserCoordinator alloc] init];
93 queue()->StartNextOverlay(web_coordinator);
94 EXPECT_TRUE(queue()->IsShowingOverlay());
95 EXPECT_EQ(web_coordinator, overlay.webCoordinator);
96 }
97
98 // Tests that OverlayWasStopped() updates state properly.
99 TEST_F(OverlayQueueTest, OverlayWasStopped) {
100 TestOverlayCoordinator* overlay =
101 [[TestOverlayCoordinator alloc] initWithWebState:web_state()];
102 queue()->AddOverlay(overlay);
103 BrowserCoordinator* web_coordinator = [[BrowserCoordinator alloc] init];
104 queue()->StartNextOverlay(web_coordinator);
105 queue()->OverlayWasStopped(overlay);
106 EXPECT_FALSE(queue()->HasQueuedOverlays());
107 EXPECT_FALSE(queue()->IsShowingOverlay());
108 }
109
110 // Tests that CancelOverlays() cancels all queued overlays for a WebState.
111 TEST_F(OverlayQueueTest, CancelOverlays) {
112 TestOverlayCoordinator* overlay0 =
113 [[TestOverlayCoordinator alloc] initWithWebState:web_state()];
114 TestOverlayCoordinator* overlay1 =
115 [[TestOverlayCoordinator alloc] initWithWebState:web_state()];
116 queue()->AddOverlay(overlay0);
117 queue()->AddOverlay(overlay1);
118 queue()->CancelOverlays();
119 EXPECT_FALSE(queue()->HasQueuedOverlays());
120 EXPECT_FALSE(queue()->IsShowingOverlay());
121 EXPECT_TRUE(overlay0.completionWasCancelled);
122 EXPECT_TRUE(overlay1.completionWasCancelled);
123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698