Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / geolocation / xwalk_geolocation_browsertest.cc
1 // Copyright (c) 2013 Intel Corporation. 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 "base/command_line.h"
6 #include "base/file_util.h"
7 #include "base/path_service.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "xwalk/runtime/browser/runtime.h"
11 #include "xwalk/runtime/common/xwalk_notification_types.h"
12 #include "xwalk/test/base/in_process_browser_test.h"
13 #include "xwalk/test/base/xwalk_test_utils.h"
14 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/test_utils.h"
25 #include "net/base/net_util.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27
28 using xwalk::NativeAppWindow;
29 using xwalk::Runtime;
30 using content::WebContents;
31 using testing::_;
32
33 class XWalkRuntimeTest : public InProcessBrowserTest {
34  public:
35   XWalkRuntimeTest() {}
36   virtual ~XWalkRuntimeTest() {
37     original_runtimes_.clear();
38     notification_observer_.reset();
39   }
40
41   // SetUpOnMainThread is called after BrowserMainRunner was initialized and
42   // just before RunTestOnMainThread (aka. TestBody).
43   virtual void SetUpOnMainThread() OVERRIDE {
44     notification_observer_.reset(
45         new content::WindowedNotificationObserver(
46           xwalk::NOTIFICATION_RUNTIME_OPENED,
47           content::NotificationService::AllSources()));
48     original_runtimes_.assign(runtimes().begin(), runtimes().end());
49   }
50
51  private:
52   RuntimeList original_runtimes_;
53   scoped_ptr<content::WindowedNotificationObserver> notification_observer_;
54 };
55
56 IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, LoadGeolocationPage) {
57   GURL url = xwalk_test_utils::GetTestURL(
58       base::FilePath(), base::FilePath().AppendASCII(
59           "geolocation/simple.html"));
60   size_t len = runtimes().size();
61   xwalk_test_utils::NavigateToURL(runtime(), url);
62   int error_code;
63   ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
64       runtime()->web_contents(),
65       "console.log('wait for result...');",
66       &error_code));
67   EXPECT_NE(error_code, -1);
68   content::RunAllPendingInMessageLoop();
69   EXPECT_EQ(len, runtimes().size());
70   runtime()->Close();
71   content::RunAllPendingInMessageLoop();
72   EXPECT_EQ(len - 1, runtimes().size());
73 }