diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-11 17:59:58 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-11 17:59:58 +0000 |
commit | f0397fa23d2eee24bd88cb22ce621aadd0d3f642 (patch) | |
tree | 83963b05b857ffd799ef283c6f89613b22422dff /chrome/browser/extensions | |
parent | b0ab4e659276d42dd13898c6fe51a019b0e62d67 (diff) | |
download | chromium_src-f0397fa23d2eee24bd88cb22ce621aadd0d3f642.zip chromium_src-f0397fa23d2eee24bd88cb22ce621aadd0d3f642.tar.gz chromium_src-f0397fa23d2eee24bd88cb22ce621aadd0d3f642.tar.bz2 |
Fix extensions_service_unittest on Linux.
I was getting failures which are not present on buildbot,
I don't know why. But with these changes it should be more solid.
This also prevents a segfault which I got (out of bounds array access).
Review URL: http://codereview.chromium.org/13258
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6792 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 039f5eb..d6dc00d 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <algorithm> #include <vector> #include "base/file_path.h" @@ -9,12 +10,22 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/string_util.h" +#include "chrome/browser/extensions/extension.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/json_value_serializer.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +namespace { + +struct ExtensionsOrder { + bool operator()(const Extension* a, const Extension* b) { + return a->name() < b->name(); + } +}; + +} // namespace // A mock implementation of ExtensionsServiceFrontendInterface for testing the // backend. @@ -49,6 +60,9 @@ class ExtensionsServiceTestFrontend extensions_.insert(extensions_.end(), new_extensions->begin(), new_extensions->end()); delete new_extensions; + // In the tests we rely on extensions being in particular order, + // which is not always the case (and is not guaranteed by used APIs). + std::stable_sort(extensions_.begin(), extensions_.end(), ExtensionsOrder()); } private: @@ -79,7 +93,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { // Note: There can be more errors if there are extra directories, like .svn // directories. EXPECT_TRUE(frontend->errors()->size() >= 2u); - EXPECT_EQ(2u, frontend->extensions()->size()); + ASSERT_EQ(2u, frontend->extensions()->size()); EXPECT_EQ(std::wstring(L"com.google.myextension1"), frontend->extensions()->at(0)->id()); @@ -87,7 +101,7 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { frontend->extensions()->at(0)->name()); EXPECT_EQ(std::wstring(L"The first extension that I made."), frontend->extensions()->at(0)->description()); - EXPECT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size()); + ASSERT_EQ(2u, frontend->extensions()->at(0)->content_scripts().size()); EXPECT_EQ(std::wstring(L"script1.user.js"), frontend->extensions()->at(0)->content_scripts().at(0)); EXPECT_EQ(std::wstring(L"script2.user.js"), @@ -99,5 +113,5 @@ TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectory) { frontend->extensions()->at(1)->name()); EXPECT_EQ(std::wstring(L""), frontend->extensions()->at(1)->description()); - EXPECT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); + ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); }; |