Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #import "ios/clean/chrome/browser/ui/overlays/overlay_queue_observer.h" | |
| 10 #import "ios/web/public/test/fakes/test_web_state.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/gtest_mac.h" | |
| 13 #include "testing/platform_test.h" | |
| 14 | |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 19 // Test OverlayQueue implementation. Subclass-specific functionality will be | |
| 20 // tested in other files. | |
| 21 class TestOverlayQueue : public OverlayQueue { | |
| 22 public: | |
| 23 void StartNextOverlay() override { OverlayWasStarted(); } | |
| 24 void AddOverlay(BrowserCoordinator* overlay) { | |
| 25 OverlayQueue::AddOverlay(overlay); | |
| 26 } | |
| 27 }; | |
| 28 | |
| 29 // Test BrowserCoordinator. | |
| 30 @interface TestBrowserCoordinator : BrowserCoordinator | |
| 31 @property(nonatomic, readonly) BOOL cancelled; | |
| 32 @end | |
| 33 | |
| 34 @implementation TestBrowserCoordinator | |
| 35 @synthesize cancelled = _cancelled; | |
| 36 - (void)cancelOverlay { | |
| 37 _cancelled = YES; | |
| 38 } | |
| 39 @end | |
| 40 | |
| 41 // Test OverlayQueueObserver. | |
| 42 class TestOverlayQueueObserver : public OverlayQueueObserver { | |
| 43 public: | |
| 44 TestOverlayQueueObserver() | |
| 45 : did_add_called_(false), | |
| 46 will_replace_called_(false), | |
| 47 stop_visible_called_(false), | |
| 48 did_cancel_called_(false) {} | |
| 49 | |
| 50 void OverlayQueueDidAddOverlay(OverlayQueue* queue) override { | |
| 51 did_add_called_ = true; | |
| 52 } | |
| 53 void OverlayQueueWillReplaceVisibleOverlay(OverlayQueue* queue) override { | |
| 54 will_replace_called_ = true; | |
| 55 } | |
| 56 void OverlayQueueDidStopVisibleOverlay(OverlayQueue* queue) override { | |
| 57 stop_visible_called_ = true; | |
| 58 } | |
| 59 void OverlayQueueDidCancelOverlays(OverlayQueue* queue) override { | |
| 60 did_cancel_called_ = true; | |
| 61 } | |
| 62 | |
| 63 bool did_add_called() { return did_add_called_; } | |
| 64 bool will_replace_called() { return will_replace_called_; } | |
| 65 bool stop_visible_called() { return stop_visible_called_; } | |
| 66 bool did_cancel_called() { return did_cancel_called_; } | |
| 67 | |
| 68 private: | |
| 69 bool did_add_called_; | |
| 70 bool will_replace_called_; | |
| 71 bool stop_visible_called_; | |
| 72 bool did_cancel_called_; | |
| 73 }; | |
| 74 | |
| 75 class OverlayQueueTest : public PlatformTest { | |
| 76 public: | |
| 77 OverlayQueueTest() : PlatformTest() { queue_.AddObserver(&observer_); } | |
| 78 | |
| 79 TestOverlayQueue& queue() { return queue_; } | |
| 80 TestOverlayQueueObserver& observer() { return observer_; } | |
| 81 | |
| 82 private: | |
| 83 TestOverlayQueue queue_; | |
| 84 TestOverlayQueueObserver observer_; | |
| 85 }; | |
| 86 | |
| 87 // Tests that adding an overlay to the queue updates state accordingly and | |
| 88 // notifies observers. | |
| 89 TEST_F(OverlayQueueTest, AddOverlay) { | |
| 90 BrowserCoordinator* overlay = | |
| 91 [[BrowserCoordinator alloc] initWithQueue:&queue()]; | |
| 92 queue().AddOverlay(overlay); | |
| 93 EXPECT_TRUE(queue().HasQueuedOverlays()); | |
| 94 EXPECT_FALSE(queue().IsShowingOverlay()); | |
| 95 EXPECT_TRUE(observer().did_add_called()); | |
| 96 } | |
| 97 | |
| 98 // Tests that OverlayWasStopped() updates state properly. | |
| 99 TEST_F(OverlayQueueTest, OverlayWasStopped) { | |
| 100 BrowserCoordinator* overlay = | |
| 101 [[BrowserCoordinator alloc] initWithQueue:&queue()]; | |
| 102 queue().AddOverlay(overlay); | |
| 103 queue().StartNextOverlay(); | |
| 104 queue().OverlayWasStopped(overlay); | |
| 105 EXPECT_FALSE(queue().HasQueuedOverlays()); | |
| 106 EXPECT_FALSE(queue().IsShowingOverlay()); | |
| 107 EXPECT_TRUE(observer().stop_visible_called()); | |
| 108 } | |
| 109 | |
| 110 // | |
|
marq (ping after 24h)
2017/06/21 09:41:53
Missing comment?
kkhorimoto
2017/06/23 06:11:16
Whoops, yes. This test is fixed now!
| |
| 111 TEST_F(OverlayQueueTest, ReplaceOverlay) { | |
| 112 BrowserCoordinator* overlay = | |
| 113 [[BrowserCoordinator alloc] initWithQueue:&queue()]; | |
| 114 queue().AddOverlay(overlay); | |
|
marq (ping after 24h)
2017/06/21 09:41:53
Missing test expectations?
kkhorimoto
2017/06/23 06:11:16
Added!
| |
| 115 } | |
| 116 | |
| 117 // Tests that CancelOverlays() cancels all queued overlays for a WebState. | |
| 118 TEST_F(OverlayQueueTest, CancelOverlays) { | |
| 119 TestBrowserCoordinator* overlay0 = | |
| 120 [[TestBrowserCoordinator alloc] initWithQueue:&queue()]; | |
| 121 TestBrowserCoordinator* overlay1 = | |
| 122 [[TestBrowserCoordinator alloc] initWithQueue:&queue()]; | |
| 123 queue().AddOverlay(overlay0); | |
| 124 queue().AddOverlay(overlay1); | |
| 125 queue().CancelOverlays(); | |
| 126 EXPECT_FALSE(queue().HasQueuedOverlays()); | |
| 127 EXPECT_FALSE(queue().IsShowingOverlay()); | |
| 128 EXPECT_TRUE(observer().did_cancel_called()); | |
| 129 EXPECT_TRUE(overlay0.cancelled); | |
| 130 EXPECT_TRUE(overlay1.cancelled); | |
| 131 } | |
| OLD | NEW |