component_installers_unittest.cc revision 9ab5563a3196760eb381d102cbb2bc0f7abc6a50
14dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala// Copyright (c) 2012 The Chromium Authors. All rights reserved.
24dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala// Use of this source code is governed by a BSD-style license that can be
34dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala// found in the LICENSE file.
44dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala
54dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "chrome/browser/component_updater/flash_component_installer.h"
64dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala
74dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/file_util.h"
84dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/files/file_path.h"
94dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/json/json_file_value_serializer.h"
104dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/memory/scoped_ptr.h"
114dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/message_loop/message_loop.h"
124dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#include "base/path_service.h"
134dda01d613890b88a9370e46ec53ef54c123f9fbAndrew Dai & Rick Kawala#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.
42// http://crbug.com/179716
43#if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
44#define MAYBE_PepperFlashCheck DISABLED_PepperFlashCheck
45// TODO(avi): Get Pepper Flash supported on the Mac 64 bit build.
46// http://crbug.com/225777
47#elif defined(OS_MACOSX) && defined(ARCH_CPU_X86_64)
48#define MAYBE_PepperFlashCheck DISABLED_PepperFlashCheck
49#else
50#define MAYBE_PepperFlashCheck PepperFlashCheck
51#endif
52
53// TODO(viettrungluu): Separate out into two separate tests; use a test fixture.
54TEST(ComponentInstallerTest, MAYBE_PepperFlashCheck) {
55  base::MessageLoop message_loop;
56  content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
57
58  ppapi::PpapiGlobals::PerThreadForTest per_thread_for_test;
59  ppapi::TestGlobals test_globals(per_thread_for_test);
60  ppapi::PpapiGlobals::SetPpapiGlobalsOnThreadForTest(&test_globals);
61
62  // The test directory is chrome/test/data/components/flapper.
63  base::FilePath manifest;
64  PathService::Get(chrome::DIR_TEST_DATA, &manifest);
65  manifest = manifest.Append(kDataPath);
66  manifest = manifest.AppendASCII("manifest.json");
67
68  if (!base::PathExists(manifest)) {
69    LOG(WARNING) << "No test manifest available. Skipping.";
70    return;
71  }
72
73  JSONFileValueSerializer serializer(manifest);
74  std::string error;
75  scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>(
76      serializer.Deserialize(NULL, &error)));
77  ASSERT_TRUE(root);
78  ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
79
80  // This checks that the whole manifest is compatible.
81  Version version;
82  EXPECT_TRUE(CheckPepperFlashManifest(*root, &version));
83  EXPECT_TRUE(version.IsValid());
84}
85