Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2006-2008 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 <vector> | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "chrome/browser/extensions/extensions_service.h" | |
| 13 #include "chrome/common/chrome_paths.h" | |
| 14 #include "chrome/common/json_value_serializer.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 class ExtensionsServiceTest : public testing::Test { | |
| 18 }; | |
| 19 | |
| 20 | |
| 21 // A mock implementation of ExtensionsServiceFrontendInterface for testing the | |
| 22 // backend. | |
| 23 class ExtensionsServiceTestFrontend | |
| 24 : public ExtensionsServiceFrontendInterface { | |
| 25 public: | |
| 26 std::vector<std::wstring>* errors() { | |
| 27 return &errors_; | |
| 28 } | |
| 29 | |
| 30 ExtensionList* extensions() { | |
| 31 return extensions_.get(); | |
| 32 } | |
| 33 | |
| 34 // ExtensionsServiceFrontendInterface | |
| 35 virtual MessageLoop* GetMessageLoop() { | |
| 36 return &message_loop_; | |
| 37 } | |
| 38 | |
| 39 virtual void OnExtensionLoadError(const std::wstring& message) { | |
| 40 errors_.push_back(message); | |
| 41 } | |
| 42 | |
| 43 virtual void OnExtensionsLoadedFromDirectory(ExtensionList* extensions) { | |
| 44 extensions_.reset(extensions); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 MessageLoop message_loop_; | |
| 49 scoped_ptr<ExtensionList> extensions_; | |
| 50 std::vector<std::wstring> errors_; | |
| 51 }; | |
| 52 | |
| 53 | |
| 54 // Test loading extensions from the profile directory. | |
| 55 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { | |
| 56 #if defined(OS_WIN) | |
| 57 std::wstring extensions_dir; | |
| 58 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_dir)); | |
| 59 FilePath manifest_path = FilePath::FromWStringHack(extensions_dir).Append( | |
| 60 FILE_PATH_LITERAL("extensions")); | |
| 61 | |
| 62 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); | |
| 63 scoped_refptr<ExtensionsServiceTestFrontend> frontend( | |
| 64 new ExtensionsServiceTestFrontend); | |
| 65 | |
| 66 std::vector<Extension*> extensions; | |
| 67 EXPECT_TRUE(backend->LoadExtensionsFromDirectory(manifest_path, | |
| 68 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); | |
| 69 frontend->GetMessageLoop()->RunAllPending(); | |
| 70 | |
| 71 // Note: There can be more errors if there are extra directories, like .svn | |
| 72 // directories. | |
| 73 EXPECT_TRUE(frontend->errors()->size() >= 2u); | |
| 74 EXPECT_EQ(Extension::kInvalidManifestError, frontend->errors()->at(0)); | |
| 75 EXPECT_EQ(Extension::kInvalidManifestError, frontend->errors()->at(1)); | |
| 76 EXPECT_EQ(2u, frontend->extensions()->size()); | |
| 77 | |
| 78 EXPECT_EQ(std::wstring(L"com.google.myextension1"), | |
| 79 frontend->extensions()->at(0)->id()); | |
| 80 EXPECT_EQ(std::wstring(L"My extension 1"), | |
| 81 frontend->extensions()->at(0)->name()); | |
| 82 EXPECT_EQ(std::wstring(L"The first extension that I made."), | |
| 83 frontend->extensions()->at(0)->description()); | |
| 84 EXPECT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size()); | |
| 85 EXPECT_EQ(std::wstring(L"script1.user.js"), | |
| 86 frontend->extensions()->at(0)->content_scripts().at(0)); | |
| 87 EXPECT_EQ(std::wstring(L"script2.user.js"), | |
| 88 frontend->extensions()->at(0)->content_scripts().at(1)); | |
| 89 | |
| 90 EXPECT_EQ(std::wstring(L"com.google.myextension2"), | |
| 91 frontend->extensions()->at(1)->id()); | |
| 92 EXPECT_EQ(std::wstring(L"My extension 2"), | |
| 93 frontend->extensions()->at(1)->name()); | |
| 94 EXPECT_EQ(std::wstring(L""), | |
| 95 frontend->extensions()->at(1)->description()); | |
| 96 EXPECT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); | |
| 97 #endif | |
| 98 }; | |
|
Erik does not do reviews
2008/12/04 22:03:06
missing newline at end of file
| |
| OLD | NEW |