Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 13258: Fix extensions_service_unittest on Linux.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 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 <algorithm>
5 #include <vector> 6 #include <vector>
6 7
7 #include "base/file_path.h" 8 #include "base/file_path.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "chrome/browser/extensions/extension.h"
12 #include "chrome/browser/extensions/extensions_service.h" 14 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/json_value_serializer.h" 16 #include "chrome/common/json_value_serializer.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
17 19
20 namespace {
21
22 struct ExtensionsOrder {
23 bool operator()(const Extension* a, const Extension* b) {
24 return a->name() < b->name();
25 }
26 };
27
28 } // namespace
18 29
19 // A mock implementation of ExtensionsServiceFrontendInterface for testing the 30 // A mock implementation of ExtensionsServiceFrontendInterface for testing the
20 // backend. 31 // backend.
21 class ExtensionsServiceTestFrontend 32 class ExtensionsServiceTestFrontend
22 : public ExtensionsServiceFrontendInterface { 33 : public ExtensionsServiceFrontendInterface {
23 public: 34 public:
24 ~ExtensionsServiceTestFrontend() { 35 ~ExtensionsServiceTestFrontend() {
25 for (ExtensionList::iterator iter = extensions_.begin(); 36 for (ExtensionList::iterator iter = extensions_.begin();
26 iter != extensions_.end(); ++iter) { 37 iter != extensions_.end(); ++iter) {
27 delete *iter; 38 delete *iter;
(...skipping 14 matching lines...) Expand all
42 } 53 }
43 54
44 virtual void OnExtensionLoadError(const std::string& message) { 55 virtual void OnExtensionLoadError(const std::string& message) {
45 errors_.push_back(message); 56 errors_.push_back(message);
46 } 57 }
47 58
48 virtual void OnExtensionsLoadedFromDirectory(ExtensionList* new_extensions) { 59 virtual void OnExtensionsLoadedFromDirectory(ExtensionList* new_extensions) {
49 extensions_.insert(extensions_.end(), new_extensions->begin(), 60 extensions_.insert(extensions_.end(), new_extensions->begin(),
50 new_extensions->end()); 61 new_extensions->end());
51 delete new_extensions; 62 delete new_extensions;
63 // In the tests we rely on extensions being in particular order,
64 // which is not always the case (and is not guaranteed by used APIs).
65 std::stable_sort(extensions_.begin(), extensions_.end(), ExtensionsOrder());
52 } 66 }
53 67
54 private: 68 private:
55 MessageLoop message_loop_; 69 MessageLoop message_loop_;
56 ExtensionList extensions_; 70 ExtensionList extensions_;
57 std::vector<std::string> errors_; 71 std::vector<std::string> errors_;
58 }; 72 };
59 73
60 // make the test a PlatformTest to setup autorelease pools properly on mac 74 // make the test a PlatformTest to setup autorelease pools properly on mac
61 typedef PlatformTest ExtensionsServiceTest; 75 typedef PlatformTest ExtensionsServiceTest;
(...skipping 10 matching lines...) Expand all
72 new ExtensionsServiceTestFrontend); 86 new ExtensionsServiceTestFrontend);
73 87
74 std::vector<Extension*> extensions; 88 std::vector<Extension*> extensions;
75 EXPECT_TRUE(backend->LoadExtensionsFromDirectory(manifest_path, 89 EXPECT_TRUE(backend->LoadExtensionsFromDirectory(manifest_path,
76 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()))); 90 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())));
77 frontend->GetMessageLoop()->RunAllPending(); 91 frontend->GetMessageLoop()->RunAllPending();
78 92
79 // Note: There can be more errors if there are extra directories, like .svn 93 // Note: There can be more errors if there are extra directories, like .svn
80 // directories. 94 // directories.
81 EXPECT_TRUE(frontend->errors()->size() >= 2u); 95 EXPECT_TRUE(frontend->errors()->size() >= 2u);
82 EXPECT_EQ(2u, frontend->extensions()->size()); 96 ASSERT_EQ(2u, frontend->extensions()->size());
83 97
84 EXPECT_EQ(std::wstring(L"com.google.myextension1"), 98 EXPECT_EQ(std::wstring(L"com.google.myextension1"),
85 frontend->extensions()->at(0)->id()); 99 frontend->extensions()->at(0)->id());
86 EXPECT_EQ(std::wstring(L"My extension 1"), 100 EXPECT_EQ(std::wstring(L"My extension 1"),
87 frontend->extensions()->at(0)->name()); 101 frontend->extensions()->at(0)->name());
88 EXPECT_EQ(std::wstring(L"The first extension that I made."), 102 EXPECT_EQ(std::wstring(L"The first extension that I made."),
89 frontend->extensions()->at(0)->description()); 103 frontend->extensions()->at(0)->description());
90 EXPECT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size()); 104 ASSERT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size());
91 EXPECT_EQ(std::wstring(L"script1.user.js"), 105 EXPECT_EQ(std::wstring(L"script1.user.js"),
92 frontend->extensions()->at(0)->content_scripts().at(0)); 106 frontend->extensions()->at(0)->content_scripts().at(0));
93 EXPECT_EQ(std::wstring(L"script2.user.js"), 107 EXPECT_EQ(std::wstring(L"script2.user.js"),
94 frontend->extensions()->at(0)->content_scripts().at(1)); 108 frontend->extensions()->at(0)->content_scripts().at(1));
95 109
96 EXPECT_EQ(std::wstring(L"com.google.myextension2"), 110 EXPECT_EQ(std::wstring(L"com.google.myextension2"),
97 frontend->extensions()->at(1)->id()); 111 frontend->extensions()->at(1)->id());
98 EXPECT_EQ(std::wstring(L"My extension 2"), 112 EXPECT_EQ(std::wstring(L"My extension 2"),
99 frontend->extensions()->at(1)->name()); 113 frontend->extensions()->at(1)->name());
100 EXPECT_EQ(std::wstring(L""), 114 EXPECT_EQ(std::wstring(L""),
101 frontend->extensions()->at(1)->description()); 115 frontend->extensions()->at(1)->description());
102 EXPECT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); 116 ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size());
103 }; 117 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698