| Index: ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue_unittest.mm | 
| diff --git a/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue_unittest.mm b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue_unittest.mm | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..e73de3e67914edcffe077ddbd12ac2cdda3bce8d | 
| --- /dev/null | 
| +++ b/ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue_unittest.mm | 
| @@ -0,0 +1,125 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#import "ios/clean/chrome/browser/ui/web_contents/overlays/web_overlay_queue.h" | 
| + | 
| +#if !defined(__has_feature) || !__has_feature(objc_arc) | 
| +#error "This file requires ARC support." | 
| +#endif | 
| + | 
| +#import "base/mac/scoped_nsobject.h" | 
| +#include "base/memory/ptr_util.h" | 
| +#import "ios/clean/chrome/browser/ui/commands/web_overlay_commands.h" | 
| +#import "ios/web/public/test/fakes/test_web_state.h" | 
| +#include "testing/gtest/include/gtest/gtest.h" | 
| +#include "testing/gtest_mac.h" | 
| +#include "testing/platform_test.h" | 
| + | 
| +// Test overlay coordinator subclass. | 
| +@interface TestWebOverlayCoordinator : WebOverlayCoordinator | 
| +// Whether the completion block has been cancelled. | 
| +@property(nonatomic, readonly) BOOL completionWasCancelled; | 
| +// The coordinator on which this has been started. | 
| +@property(nonatomic, readonly) BrowserCoordinator* webCoordinator; | 
| +@end | 
| + | 
| +@implementation TestWebOverlayCoordinator | 
| +@synthesize completionWasCancelled = _completionWasCancelled; | 
| +@synthesize webCoordinator = _webCoordinator; | 
| + | 
| +- (void)cancelWebKitCompletion { | 
| +  _completionWasCancelled = YES; | 
| +} | 
| + | 
| +- (void)startOverlayingWebCoordinator:(BrowserCoordinator*)webCoordinator { | 
| +  _webCoordinator = webCoordinator; | 
| +} | 
| + | 
| +@end | 
| + | 
| +// Test overlay scheduler subclass. | 
| +@interface TestWebOverlayScheduler : NSObject<WebOverlaySchedulerCommands> | 
| +@property(nonatomic, readonly) web::WebState* nextWebState; | 
| +@end | 
| + | 
| +@implementation TestWebOverlayScheduler | 
| +@synthesize nextWebState = _nextWebState; | 
| + | 
| +- (void)scheduleWebOverlayForWebState:(web::WebState*)webState { | 
| +  _nextWebState = webState; | 
| +} | 
| +- (void)webOverlayWasStoppedForWebState:(web::WebState*)webState { | 
| +} | 
| +- (void)cancelWebOverlaysForWebState:(web::WebState*)webState { | 
| +} | 
| +@end | 
| + | 
| +class WebOverlayQueueTest : public PlatformTest { | 
| + public: | 
| +  WebOverlayQueueTest() | 
| +      : PlatformTest(), scheduler_([[TestWebOverlayScheduler alloc] init]) { | 
| +    WebOverlayQueue::CreateForWebState(&web_state_, scheduler_); | 
| +  } | 
| + | 
| +  web::WebState* web_state() { return &web_state_; } | 
| + | 
| +  WebOverlayQueue* queue() { | 
| +    return WebOverlayQueue::FromWebState(&web_state_); | 
| +  } | 
| + | 
| +  TestWebOverlayScheduler* scheduler() { return scheduler_; } | 
| + | 
| + private: | 
| +  web::TestWebState web_state_; | 
| +  base::scoped_nsobject<TestWebOverlayScheduler> scheduler_; | 
| +}; | 
| + | 
| +// Tests that adding an overlay to the queue updates state accordingly and | 
| +// dispatches a |-scheduleWebOverlayForWebState:| command. | 
| +TEST_F(WebOverlayQueueTest, AddOverlay) { | 
| +  TestWebOverlayCoordinator* overlay = | 
| +      [[TestWebOverlayCoordinator alloc] initWithWebState:web_state()]; | 
| +  queue()->AddWebOverlay(overlay); | 
| +  EXPECT_TRUE(queue()->HasQueuedOverlays()); | 
| +  EXPECT_FALSE(queue()->IsShowingOverlay()); | 
| +  EXPECT_EQ(web_state(), scheduler().nextWebState); | 
| +} | 
| + | 
| +// Tests that starting an overlay updates state and starts the queued overlay. | 
| +TEST_F(WebOverlayQueueTest, StartOverlay) { | 
| +  TestWebOverlayCoordinator* overlay = | 
| +      [[TestWebOverlayCoordinator alloc] initWithWebState:web_state()]; | 
| +  queue()->AddWebOverlay(overlay); | 
| +  BrowserCoordinator* web_coordinator = [[BrowserCoordinator alloc] init]; | 
| +  queue()->StartNextOverlay(web_coordinator); | 
| +  EXPECT_TRUE(queue()->IsShowingOverlay()); | 
| +  EXPECT_EQ(web_coordinator, overlay.webCoordinator); | 
| +} | 
| + | 
| +// Tests that WebOverlayWasStopped() updates state properly. | 
| +TEST_F(WebOverlayQueueTest, OverlayWasStopped) { | 
| +  TestWebOverlayCoordinator* overlay = | 
| +      [[TestWebOverlayCoordinator alloc] initWithWebState:web_state()]; | 
| +  queue()->AddWebOverlay(overlay); | 
| +  BrowserCoordinator* web_coordinator = [[BrowserCoordinator alloc] init]; | 
| +  queue()->StartNextOverlay(web_coordinator); | 
| +  queue()->WebOverlayWasStopped(overlay); | 
| +  EXPECT_FALSE(queue()->HasQueuedOverlays()); | 
| +  EXPECT_FALSE(queue()->IsShowingOverlay()); | 
| +} | 
| + | 
| +// Tests that CancelOverlays() cancels all queued overlays for a WebState. | 
| +TEST_F(WebOverlayQueueTest, CancelOverlays) { | 
| +  TestWebOverlayCoordinator* overlay0 = | 
| +      [[TestWebOverlayCoordinator alloc] initWithWebState:web_state()]; | 
| +  TestWebOverlayCoordinator* overlay1 = | 
| +      [[TestWebOverlayCoordinator alloc] initWithWebState:web_state()]; | 
| +  queue()->AddWebOverlay(overlay0); | 
| +  queue()->AddWebOverlay(overlay1); | 
| +  queue()->CancelOverlays(); | 
| +  EXPECT_FALSE(queue()->HasQueuedOverlays()); | 
| +  EXPECT_FALSE(queue()->IsShowingOverlay()); | 
| +  EXPECT_TRUE(overlay0.completionWasCancelled); | 
| +  EXPECT_TRUE(overlay1.completionWasCancelled); | 
| +} | 
|  |