| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/manifest.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/mock_host_resolver.h" | 20 #include "net/base/mock_host_resolver.h" |
| 20 | 21 |
| 21 class ChromeAppAPITest : public ExtensionBrowserTest { | 22 class ChromeAppAPITest : public ExtensionBrowserTest { |
| 22 protected: | 23 protected: |
| 23 bool IsAppInstalled() { | 24 bool IsAppInstalled() { |
| 24 std::wstring get_app_is_installed = | 25 std::wstring get_app_is_installed = |
| 25 L"window.domAutomationController.send(window.chrome.app.isInstalled);"; | 26 L"window.domAutomationController.send(window.chrome.app.isInstalled);"; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Check that an app page returns the correct result for | 92 // Check that an app page returns the correct result for |
| 92 // chrome.app.getDetails(). | 93 // chrome.app.getDetails(). |
| 93 ui_test_utils::NavigateToURL(browser(), app_url); | 94 ui_test_utils::NavigateToURL(browser(), app_url); |
| 94 ASSERT_TRUE( | 95 ASSERT_TRUE( |
| 95 ui_test_utils::ExecuteJavaScriptAndExtractString( | 96 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 96 browser()->GetSelectedTabContents()->render_view_host(), | 97 browser()->GetSelectedTabContents()->render_view_host(), |
| 97 L"", get_app_details, &result)); | 98 L"", get_app_details, &result)); |
| 98 scoped_ptr<DictionaryValue> app_details( | 99 scoped_ptr<DictionaryValue> app_details( |
| 99 static_cast<DictionaryValue*>( | 100 static_cast<DictionaryValue*>( |
| 100 base::JSONReader::Read(result, false /* allow trailing comma */))); | 101 base::JSONReader::Read(result, false /* allow trailing comma */))); |
| 101 // extension->manifest_value() does not contain the id. | 102 // extension->manifest() does not contain the id. |
| 102 app_details->Remove("id", NULL); | 103 app_details->Remove("id", NULL); |
| 103 EXPECT_TRUE(app_details.get()); | 104 EXPECT_TRUE(app_details.get()); |
| 104 EXPECT_TRUE(app_details->Equals(extension->manifest_value())); | 105 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); |
| 105 | 106 |
| 106 // Try to change app.isInstalled. Should silently fail, so | 107 // Try to change app.isInstalled. Should silently fail, so |
| 107 // that isInstalled should have the initial value. | 108 // that isInstalled should have the initial value. |
| 108 ASSERT_TRUE( | 109 ASSERT_TRUE( |
| 109 ui_test_utils::ExecuteJavaScriptAndExtractString( | 110 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 110 browser()->GetSelectedTabContents()->render_view_host(), | 111 browser()->GetSelectedTabContents()->render_view_host(), |
| 111 L"", | 112 L"", |
| 112 L"window.domAutomationController.send(" | 113 L"window.domAutomationController.send(" |
| 113 L" function() {" | 114 L" function() {" |
| 114 L" var value = window.chrome.app.isInstalled;" | 115 L" var value = window.chrome.app.isInstalled;" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 L" JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))"; | 171 L" JSON.stringify(chrome.app.getDetailsForFrame(frames[0])))"; |
| 171 std::string json; | 172 std::string json; |
| 172 ASSERT_TRUE( | 173 ASSERT_TRUE( |
| 173 ui_test_utils::ExecuteJavaScriptAndExtractString( | 174 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 174 browser()->GetSelectedTabContents()->render_view_host(), | 175 browser()->GetSelectedTabContents()->render_view_host(), |
| 175 L"", get_details_for_frame, &json)); | 176 L"", get_details_for_frame, &json)); |
| 176 | 177 |
| 177 scoped_ptr<DictionaryValue> app_details( | 178 scoped_ptr<DictionaryValue> app_details( |
| 178 static_cast<DictionaryValue*>( | 179 static_cast<DictionaryValue*>( |
| 179 base::JSONReader::Read(json, false /* allow trailing comma */))); | 180 base::JSONReader::Read(json, false /* allow trailing comma */))); |
| 180 // extension->manifest_value() does not contain the id. | 181 // extension->manifest() does not contain the id. |
| 181 app_details->Remove("id", NULL); | 182 app_details->Remove("id", NULL); |
| 182 EXPECT_TRUE(app_details.get()); | 183 EXPECT_TRUE(app_details.get()); |
| 183 EXPECT_TRUE(app_details->Equals(extension->manifest_value())); | 184 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); |
| 184 } | 185 } |
| OLD | NEW |