From c407dc5cd9bdc5668497f21b26b09d988ab439de Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 29 Jul 2010 17:14:53 +0100 Subject: Merge Chromium src@r53293 Change-Id: Ia79acf8670f385cee48c45b0a75371d8e950af34 --- chrome/browser/extensions/extension_ui_unittest.cc | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 chrome/browser/extensions/extension_ui_unittest.cc (limited to 'chrome/browser/extensions/extension_ui_unittest.cc') diff --git a/chrome/browser/extensions/extension_ui_unittest.cc b/chrome/browser/extensions/extension_ui_unittest.cc new file mode 100644 index 0000000..96af1c8 --- /dev/null +++ b/chrome/browser/extensions/extension_ui_unittest.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/path_service.h" +#include "base/string_util.h" +#include "chrome/browser/extensions/extensions_ui.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/json_value_serializer.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + static DictionaryValue* DeserializeJSONTestData(const FilePath& path, + std::string *error) { + Value* value; + + JSONFileValueSerializer serializer(path); + value = serializer.Deserialize(NULL, error); + + return static_cast(value); + } + + static bool CompareExpectedAndActualOutput( + const FilePath& extension_path, + const std::vector& pages, + const FilePath& expected_output_path) { + // TODO(rafaelw): Using the extension_path passed in above, causes this + // unit test to fail on linux. The Values come back valid, but the + // UserScript.path() values return "". +#if defined(OS_WIN) + FilePath path(FILE_PATH_LITERAL("c:\\foo")); +#elif defined(OS_POSIX) + FilePath path(FILE_PATH_LITERAL("/foo")); +#endif + Extension extension(path); + std::string error; + + FilePath manifest_path = extension_path.Append( + Extension::kManifestFilename); + scoped_ptr extension_data(DeserializeJSONTestData( + manifest_path, &error)); + EXPECT_EQ("", error); + EXPECT_TRUE(extension.InitFromValue(*extension_data, true, &error)); + EXPECT_EQ("", error); + + scoped_ptr expected_output_data(DeserializeJSONTestData( + expected_output_path, &error)); + EXPECT_EQ("", error); + + // Produce test output. + scoped_ptr actual_output_data( + ExtensionsDOMHandler::CreateExtensionDetailValue(NULL, &extension, + pages, true)); + + // Compare the outputs. + return expected_output_data->Equals(actual_output_data.get()); + } +} // namespace + +TEST(ExtensionUITest, GenerateExtensionsJSONData) { + FilePath data_test_dir_path, extension_path, expected_output_path; + EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); + + // Test Extension1 + extension_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("good") + .AppendASCII("Extensions") + .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") + .AppendASCII("1.0.0.0"); + + std::vector pages; + pages.push_back(ExtensionPage( + GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/bar.html"), + 42, 88)); + pages.push_back(ExtensionPage( + GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/dog.html"), + 0, 0)); + + expected_output_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("ui") + .AppendASCII("create_extension_detail_value_expected_output") + .AppendASCII("good-extension1.json"); + + EXPECT_TRUE(CompareExpectedAndActualOutput(extension_path, pages, + expected_output_path)) << extension_path.value(); + + // Test Extension2 + extension_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("good") + .AppendASCII("Extensions") + .AppendASCII("hpiknbiabeeppbpihjehijgoemciehgk") + .AppendASCII("2"); + + expected_output_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("ui") + .AppendASCII("create_extension_detail_value_expected_output") + .AppendASCII("good-extension2.json"); + + // It's OK to have duplicate URLs, so long as the IDs are different. + pages[1].url = pages[0].url; + + EXPECT_TRUE(CompareExpectedAndActualOutput(extension_path, pages, + expected_output_path)) << extension_path.value(); + + // Test Extension3 + extension_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("good") + .AppendASCII("Extensions") + .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") + .AppendASCII("1.0"); + + expected_output_path = data_test_dir_path.AppendASCII("extensions") + .AppendASCII("ui") + .AppendASCII("create_extension_detail_value_expected_output") + .AppendASCII("good-extension3.json"); + + pages.clear(); + + EXPECT_TRUE(CompareExpectedAndActualOutput(extension_path, pages, + expected_output_path)) << extension_path.value(); +} -- cgit v1.1