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
3 // found in the LICENSE file.
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/test/chromedriver/chrome/status.h"
10 #include "chrome/test/chromedriver/chrome/stub_chrome.h"
11 #include "chrome/test/chromedriver/chrome/stub_web_view.h"
12 #include "chrome/test/chromedriver/session.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 class MockChrome : public StubChrome {
19 MockChrome() : web_view_("1") {}
20 virtual ~MockChrome() {}
22 virtual Status GetWebViewById(const std::string& id,
23 WebView** web_view) OVERRIDE {
24 if (id == web_view_.GetId()) {
25 *web_view = &web_view_;
28 return Status(kUnknownError);
32 StubWebView web_view_;
37 TEST(Session, GetTargetWindowNoChrome) {
40 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
43 TEST(Session, GetTargetWindowTargetWindowClosed) {
44 scoped_ptr<Chrome> chrome(new MockChrome());
45 Session session("1", chrome.Pass());
48 ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
51 TEST(Session, GetTargetWindowTargetWindowStillOpen) {
52 scoped_ptr<Chrome> chrome(new MockChrome());
53 Session session("1", chrome.Pass());
55 WebView* web_view = NULL;
56 ASSERT_EQ(kOk, session.GetTargetWindow(&web_view).code());
57 ASSERT_TRUE(web_view);