Home | History | Annotate | Download | only in runtime
      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 "chrome/browser/apps/app_browsertest_util.h"
      6 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
      7 #include "chrome/browser/extensions/extension_apitest.h"
      8 #include "chrome/browser/extensions/extension_function_test_utils.h"
      9 #include "chrome/test/base/ui_test_utils.h"
     10 #include "net/test/embedded_test_server/embedded_test_server.h"
     11 
     12 // Tests the privileged components of chrome.runtime.
     13 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimePrivileged) {
     14   ASSERT_TRUE(RunExtensionTest("runtime/privileged")) << message_;
     15 }
     16 
     17 // Tests the unprivileged components of chrome.runtime.
     18 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeUnprivileged) {
     19   ASSERT_TRUE(StartEmbeddedTestServer());
     20   ASSERT_TRUE(
     21       LoadExtension(test_data_dir_.AppendASCII("runtime/content_script")));
     22 
     23   // The content script runs on webpage.html.
     24   ResultCatcher catcher;
     25   ui_test_utils::NavigateToURL(browser(),
     26                                embedded_test_server()->GetURL("/webpage.html"));
     27   EXPECT_TRUE(catcher.GetNextResult()) << message_;
     28 }
     29 
     30 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeUninstallUrl) {
     31   ASSERT_TRUE(LoadExtension(
     32       test_data_dir_.AppendASCII("runtime").AppendASCII("uninstall_url").
     33           AppendASCII("sets_uninstall_url")));
     34   ASSERT_TRUE(RunExtensionTest("runtime/uninstall_url")) << message_;
     35 }
     36 
     37 namespace extensions {
     38 
     39 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeGetPlatformInfo) {
     40   scoped_ptr<base::Value> result(
     41       extension_function_test_utils::RunFunctionAndReturnSingleResult(
     42           new RuntimeGetPlatformInfoFunction(),
     43           "[]",
     44           browser()));
     45   ASSERT_TRUE(result.get() != NULL);
     46   base::DictionaryValue* dict =
     47       extension_function_test_utils::ToDictionary(result.get());
     48   ASSERT_TRUE(dict != NULL);
     49   EXPECT_TRUE(dict->HasKey("os"));
     50   EXPECT_TRUE(dict->HasKey("arch"));
     51   EXPECT_TRUE(dict->HasKey("nacl_arch"));
     52 }
     53 
     54 // Tests chrome.runtime.getPackageDirectory with an app.
     55 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
     56                        ChromeRuntimeGetPackageDirectoryEntryApp) {
     57   ClearCommandLineArgs();
     58   ASSERT_TRUE(RunPlatformAppTest("api_test/runtime/get_package_directory/app"))
     59       << message_;
     60 }
     61 
     62 // Tests chrome.runtime.getPackageDirectory with an extension.
     63 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
     64                        ChromeRuntimeGetPackageDirectoryEntryExtension) {
     65   ASSERT_TRUE(RunExtensionTest("runtime/get_package_directory/extension"))
     66       << message_;
     67 }
     68 
     69 }  // namespace extensions
     70