Home | History | Annotate | Download | only in chromedriver
      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.
      4 
      5 #include <list>
      6 #include <string>
      7 
      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"
     14 
     15 namespace {
     16 
     17 class MockChrome : public StubChrome {
     18  public:
     19   MockChrome() : web_view_("1") {}
     20   virtual ~MockChrome() {}
     21 
     22   virtual Status GetWebViewById(const std::string& id,
     23                                 WebView** web_view) OVERRIDE {
     24     if (id == web_view_.GetId()) {
     25       *web_view = &web_view_;
     26       return Status(kOk);
     27     }
     28     return Status(kUnknownError);
     29   }
     30 
     31  private:
     32   StubWebView web_view_;
     33 };
     34 
     35 }  // namespace
     36 
     37 TEST(Session, GetTargetWindowNoChrome) {
     38   Session session("1");
     39   WebView* web_view;
     40   ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
     41 }
     42 
     43 TEST(Session, GetTargetWindowTargetWindowClosed) {
     44   scoped_ptr<Chrome> chrome(new MockChrome());
     45   Session session("1", chrome.Pass());
     46   session.window = "2";
     47   WebView* web_view;
     48   ASSERT_EQ(kNoSuchWindow, session.GetTargetWindow(&web_view).code());
     49 }
     50 
     51 TEST(Session, GetTargetWindowTargetWindowStillOpen) {
     52   scoped_ptr<Chrome> chrome(new MockChrome());
     53   Session session("1", chrome.Pass());
     54   session.window = "1";
     55   WebView* web_view = NULL;
     56   ASSERT_EQ(kOk, session.GetTargetWindow(&web_view).code());
     57   ASSERT_TRUE(web_view);
     58 }
     59