component_installers_unittest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 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 "chrome/browser/component_updater/flash_component_installer.h"
6
7#include "base/file_util.h"
8#include "base/files/file_path.h"
9#include "base/json/json_file_value_serializer.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/message_loop.h"
12#include "base/path_service.h"
13#include "base/version.h"
14#include "build/build_config.h"
15#include "chrome/common/chrome_paths.h"
16#include "content/public/test/test_browser_thread.h"
17#include "ppapi/shared_impl/test_globals.h"
18
19#include "testing/gtest/include/gtest/gtest.h"
20
21using content::BrowserThread;
22
23namespace {
24// File name of the Pepper Flash plugin on different platforms.
25const base::FilePath::CharType kDataPath[] =
26#if defined(OS_MACOSX)
27    FILE_PATH_LITERAL("components/flapper/mac");
28#elif defined(OS_WIN)
29    FILE_PATH_LITERAL("components\\flapper\\windows");
30#else  // OS_LINUX, etc.
31#if defined(ARCH_CPU_X86)
32    FILE_PATH_LITERAL("components/flapper/linux");
33#elif defined(ARCH_CPU_X86_64)
34    FILE_PATH_LITERAL("components/flapper/linux_x64");
35#else
36    FILE_PATH_LITERAL("components/flapper/NONEXISTENT");
37#endif
38#endif
39}
40
41// TODO(jschuh): Get Pepper Flash supported on Win64 build. crbug.com/179716
42#if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
43#define MAYBE_PepperFlashCheck DISABLED_PepperFlashCheck
44#else
45#define MAYBE_PepperFlashCheck PepperFlashCheck
46#endif
47
48// TODO(viettrungluu): Separate out into two separate tests; use a test fixture.
49TEST(ComponentInstallerTest, MAYBE_PepperFlashCheck) {
50  MessageLoop message_loop;
51  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
52
53  ppapi::PpapiGlobals::PerThreadForTest per_thread_for_test;
54  ppapi::TestGlobals test_globals(per_thread_for_test);
55  ppapi::PpapiGlobals::SetPpapiGlobalsOnThreadForTest(&test_globals);
56
57  // The test directory is chrome/test/data/components/flapper.
58  base::FilePath manifest;
59  PathService::Get(chrome::DIR_TEST_DATA, &manifest);
60  manifest = manifest.Append(kDataPath);
61  manifest = manifest.AppendASCII("manifest.json");
62
63  if (!file_util::PathExists(manifest)) {
64    LOG(WARNING) << "No test manifest available. Skipping.";
65    return;
66  }
67
68  JSONFileValueSerializer serializer(manifest);
69  std::string error;
70  scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error));
71  ASSERT_TRUE(root.get() != NULL);
72  ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
73
74  // This checks that the whole manifest is compatible.
75  Version version;
76  EXPECT_TRUE(CheckPepperFlashManifest(
77      static_cast<base::DictionaryValue*>(root.get()), &version));
78  EXPECT_TRUE(version.IsValid());
79}
80