| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/chromedriver/session.h" |
| 6 |
| 5 #include <string> | 7 #include <string> |
| 8 #include <utility> |
| 6 | 9 |
| 7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/test/chromedriver/chrome/status.h" | 11 #include "chrome/test/chromedriver/chrome/status.h" |
| 9 #include "chrome/test/chromedriver/chrome/stub_chrome.h" | 12 #include "chrome/test/chromedriver/chrome/stub_chrome.h" |
| 10 #include "chrome/test/chromedriver/chrome/stub_web_view.h" | 13 #include "chrome/test/chromedriver/chrome/stub_web_view.h" |
| 11 #include "chrome/test/chromedriver/session.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 class MockChrome : public StubChrome { | 18 class MockChrome : public StubChrome { |
| 17 public: | 19 public: |
| 18 MockChrome() : web_view_("1") {} | 20 MockChrome() : web_view_("1") {} |
| 19 ~MockChrome() override {} | 21 ~MockChrome() override {} |
| 20 | 22 |
| 21 Status GetWebViewById(const std::string& id, WebView** web_view) override { | 23 Status GetWebViewById(const std::string& id, WebView** web_view) override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 } // namespace | 35 } // namespace |
| 34 | 36 |
| 35 TEST(Session, GetTargetWindowNoChrome) { | 37 TEST(Session, GetTargetWindowNoChrome) { |
| 36 Session session("1"); | 38 Session session("1"); |
| 37 WebView* web_view; | 39 WebView* web_view; |
| 38 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); | 40 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 TEST(Session, GetTargetWindowTargetWindowClosed) { | 43 TEST(Session, GetTargetWindowTargetWindowClosed) { |
| 42 scoped_ptr<Chrome> chrome(new MockChrome()); | 44 scoped_ptr<Chrome> chrome(new MockChrome()); |
| 43 Session session("1", chrome.Pass()); | 45 Session session("1", std::move(chrome)); |
| 44 session.window = "2"; | 46 session.window = "2"; |
| 45 WebView* web_view; | 47 WebView* web_view; |
| 46 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); | 48 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code()); |
| 47 } | 49 } |
| 48 | 50 |
| 49 TEST(Session, GetTargetWindowTargetWindowStillOpen) { | 51 TEST(Session, GetTargetWindowTargetWindowStillOpen) { |
| 50 scoped_ptr<Chrome> chrome(new MockChrome()); | 52 scoped_ptr<Chrome> chrome(new MockChrome()); |
| 51 Session session("1", chrome.Pass()); | 53 Session session("1", std::move(chrome)); |
| 52 session.window = "1"; | 54 session.window = "1"; |
| 53 WebView* web_view = NULL; | 55 WebView* web_view = NULL; |
| 54 ASSERT_EQ(kOk, session.GetTargetWindow(&web_view).code()); | 56 ASSERT_EQ(kOk, session.GetTargetWindow(&web_view).code()); |
| 55 ASSERT_TRUE(web_view); | 57 ASSERT_TRUE(web_view); |
| 56 } | 58 } |
| 57 | 59 |
| 58 TEST(Session, SwitchToParentFrame) { | 60 TEST(Session, SwitchToParentFrame) { |
| 59 scoped_ptr<Chrome> chrome(new MockChrome()); | 61 scoped_ptr<Chrome> chrome(new MockChrome()); |
| 60 Session session("1", chrome.Pass()); | 62 Session session("1", std::move(chrome)); |
| 61 | 63 |
| 62 // Initial frame should be top frame. | 64 // Initial frame should be top frame. |
| 63 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 65 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 64 | 66 |
| 65 // Switching to parent frame should be a no-op. | 67 // Switching to parent frame should be a no-op. |
| 66 session.SwitchToParentFrame(); | 68 session.SwitchToParentFrame(); |
| 67 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 69 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 68 | 70 |
| 69 session.SwitchToSubFrame("1.1", std::string()); | 71 session.SwitchToSubFrame("1.1", std::string()); |
| 70 ASSERT_EQ("1.1", session.GetCurrentFrameId()); | 72 ASSERT_EQ("1.1", session.GetCurrentFrameId()); |
| 71 session.SwitchToParentFrame(); | 73 session.SwitchToParentFrame(); |
| 72 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 74 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 73 | 75 |
| 74 session.SwitchToSubFrame("2.1", std::string()); | 76 session.SwitchToSubFrame("2.1", std::string()); |
| 75 ASSERT_EQ("2.1", session.GetCurrentFrameId()); | 77 ASSERT_EQ("2.1", session.GetCurrentFrameId()); |
| 76 session.SwitchToSubFrame("2.2", std::string()); | 78 session.SwitchToSubFrame("2.2", std::string()); |
| 77 ASSERT_EQ("2.2", session.GetCurrentFrameId()); | 79 ASSERT_EQ("2.2", session.GetCurrentFrameId()); |
| 78 session.SwitchToParentFrame(); | 80 session.SwitchToParentFrame(); |
| 79 ASSERT_EQ("2.1", session.GetCurrentFrameId()); | 81 ASSERT_EQ("2.1", session.GetCurrentFrameId()); |
| 80 session.SwitchToParentFrame(); | 82 session.SwitchToParentFrame(); |
| 81 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 83 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 82 } | 84 } |
| 83 | 85 |
| 84 TEST(Session, SwitchToTopFrame) { | 86 TEST(Session, SwitchToTopFrame) { |
| 85 scoped_ptr<Chrome> chrome(new MockChrome()); | 87 scoped_ptr<Chrome> chrome(new MockChrome()); |
| 86 Session session("1", chrome.Pass()); | 88 Session session("1", std::move(chrome)); |
| 87 | 89 |
| 88 // Initial frame should be top frame. | 90 // Initial frame should be top frame. |
| 89 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 91 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 90 | 92 |
| 91 // Switching to top frame should be a no-op. | 93 // Switching to top frame should be a no-op. |
| 92 session.SwitchToTopFrame(); | 94 session.SwitchToTopFrame(); |
| 93 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 95 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 94 | 96 |
| 95 session.SwitchToSubFrame("3.1", std::string()); | 97 session.SwitchToSubFrame("3.1", std::string()); |
| 96 ASSERT_EQ("3.1", session.GetCurrentFrameId()); | 98 ASSERT_EQ("3.1", session.GetCurrentFrameId()); |
| 97 session.SwitchToSubFrame("3.2", std::string()); | 99 session.SwitchToSubFrame("3.2", std::string()); |
| 98 ASSERT_EQ("3.2", session.GetCurrentFrameId()); | 100 ASSERT_EQ("3.2", session.GetCurrentFrameId()); |
| 99 session.SwitchToTopFrame(); | 101 session.SwitchToTopFrame(); |
| 100 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); | 102 ASSERT_EQ(std::string(), session.GetCurrentFrameId()); |
| 101 } | 103 } |
| OLD | NEW |