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"
14 class CRWJSInvokeParameterQueueTest : public PlatformTest {
16 CRWJSInvokeParameterQueueTest() {}
17 ~CRWJSInvokeParameterQueueTest() override {}
18 void SetUp() override;
19 void TearDown() override;
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"
46 [js_invoke_parameter_queue_ addCommandString:@"command2"
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]);