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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "chrome/test/chromedriver/session.h" | 10 #include "chrome/test/chromedriver/session.h" |
| 11 #include "chrome/test/chromedriver/status.h" |
| 12 #include "chrome/test/chromedriver/stub_chrome.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
| 15 namespace { |
| 16 |
| 17 class ValidFrameChrome : public StubChrome { |
| 18 public: |
| 19 ValidFrameChrome() {} |
| 20 virtual ~ValidFrameChrome() {} |
| 21 |
| 22 virtual Status GetMainFrame(std::string* frame_id) OVERRIDE { |
| 23 *frame_id = "main"; |
| 24 return Status(kOk); |
| 25 } |
| 26 |
| 27 virtual Status WaitForPendingNavigations( |
| 28 const std::string& frame_id) OVERRIDE { |
| 29 if (frame_id == "") |
| 30 return Status(kUnknownError, "frame_id was empty"); |
| 31 return Status(kOk); |
| 32 } |
| 33 }; |
| 34 |
| 35 } // namespace |
| 36 |
13 TEST(SessionAccessorTest, LocksSession) { | 37 TEST(SessionAccessorTest, LocksSession) { |
14 scoped_ptr<Session> scoped_session(new Session("id")); | 38 scoped_ptr<Session> scoped_session(new Session("id")); |
15 Session* session = scoped_session.get(); | 39 Session* session = scoped_session.get(); |
16 scoped_refptr<SessionAccessor> accessor( | 40 scoped_refptr<SessionAccessor> accessor( |
17 new SessionAccessorImpl(scoped_session.Pass())); | 41 new SessionAccessorImpl(scoped_session.Pass())); |
18 scoped_ptr<base::AutoLock> lock; | 42 scoped_ptr<base::AutoLock> lock; |
19 ASSERT_EQ(session, accessor->Access(&lock)); | 43 ASSERT_EQ(session, accessor->Access(&lock)); |
20 ASSERT_TRUE(lock.get()); | 44 ASSERT_TRUE(lock.get()); |
21 } | 45 } |
| 46 |
| 47 TEST(Session, WaitForPendingNavigationsNoChrome) { |
| 48 Session session("id"); |
| 49 ASSERT_TRUE(session.WaitForPendingNavigations().IsOk()); |
| 50 } |
| 51 |
| 52 TEST(Session, WaitForPendingNavigations) { |
| 53 scoped_ptr<Chrome> chrome(new ValidFrameChrome()); |
| 54 Session session("id", chrome.Pass()); |
| 55 session.frame = "f"; |
| 56 ASSERT_TRUE(session.WaitForPendingNavigations().IsOk()); |
| 57 } |
| 58 |
| 59 TEST(Session, WaitForPendingNavigationsMainFrame) { |
| 60 scoped_ptr<Chrome> chrome(new ValidFrameChrome()); |
| 61 Session session("id", chrome.Pass()); |
| 62 session.frame = ""; |
| 63 ASSERT_TRUE(session.WaitForPendingNavigations().IsOk()); |
| 64 } |
OLD | NEW |