Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / web / web_state / js / crw_js_invoke_parameter_queue_unittest.mm
blob5be2fa86e326d10cb7a3346d8d4aad42098b0f21
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
3 // found in the LICENSE file.
5 #import "ios/web/web_state/js/crw_js_invoke_parameter_queue.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "testing/gtest_mac.h"
9 #include "testing/platform_test.h"
10 #include "url/gurl.h"
12 namespace {
14 class CRWJSInvokeParameterQueueTest : public PlatformTest {
15  public:
16   CRWJSInvokeParameterQueueTest() {}
17   ~CRWJSInvokeParameterQueueTest() override {}
18   void SetUp() override;
19   void TearDown() override;
21  protected:
22   base::scoped_nsobject<CRWJSInvokeParameterQueue> js_invoke_parameter_queue_;
25 void CRWJSInvokeParameterQueueTest::SetUp() {
26   js_invoke_parameter_queue_.reset([[CRWJSInvokeParameterQueue alloc] init]);
29 void CRWJSInvokeParameterQueueTest::TearDown() {
30   js_invoke_parameter_queue_.reset();
33 TEST_F(CRWJSInvokeParameterQueueTest, testRemoveFromEmptyQueue) {
34   EXPECT_TRUE([js_invoke_parameter_queue_ isEmpty]);
35   EXPECT_NSEQ(nil, [js_invoke_parameter_queue_ popInvokeParameters]);
38 TEST_F(CRWJSInvokeParameterQueueTest, testFifoOrdering) {
39   GURL url1("http://url1.example.com/path1");
40   GURL url2("https://url2.example.com/path2");
41   EXPECT_TRUE([js_invoke_parameter_queue_ isEmpty]);
42   [js_invoke_parameter_queue_ addCommandString:@"command1"
43                              userIsInteracting:YES
44                                      originURL:url1
45                                    forWindowId:@"one"];
46   [js_invoke_parameter_queue_ addCommandString:@"command2"
47                              userIsInteracting:NO
48                                      originURL:url2
49                                    forWindowId:@"two"];
50   EXPECT_FALSE([js_invoke_parameter_queue_ isEmpty]);
52   CRWJSInvokeParameters* param1 =
53       [js_invoke_parameter_queue_ popInvokeParameters];
54   EXPECT_NSEQ(@"command1", [param1 commandString]);
55   EXPECT_TRUE([param1 userIsInteracting]);
56   EXPECT_EQ(url1, [param1 originURL]);
57   EXPECT_NSEQ(@"one", [param1 windowId]);
59   CRWJSInvokeParameters* param2 =
60       [js_invoke_parameter_queue_ popInvokeParameters];
61   EXPECT_NSEQ(@"command2", [param2 commandString]);
62   EXPECT_FALSE([param2 userIsInteracting]);
63   EXPECT_EQ(url2, [param2 originURL]);
64   EXPECT_NSEQ(@"two", [param2 windowId]);
66   EXPECT_TRUE([js_invoke_parameter_queue_ isEmpty]);
67   EXPECT_NSEQ(nil, [js_invoke_parameter_queue_ popInvokeParameters]);
70 }  // namespace