• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 "ui/compositor/test/context_factories_for_test.h"
6 
7 #include "base/command_line.h"
8 #include "base/sys_info.h"
9 #include "ui/compositor/compositor.h"
10 #include "ui/compositor/compositor_switches.h"
11 #include "ui/compositor/test/default_context_factory.h"
12 #include "ui/compositor/test/test_context_factory.h"
13 
14 namespace ui {
15 
16 static ContextFactory* g_implicit_factory = NULL;
17 
18 // static
InitializeContextFactoryForTests(bool allow_test_contexts)19 void InitializeContextFactoryForTests(bool allow_test_contexts) {
20   DCHECK(!g_implicit_factory) <<
21       "ContextFactory for tests already initialized.";
22 
23   bool use_test_contexts = true;
24 
25   // Always use test contexts unless the disable command line flag is used.
26   CommandLine* command_line = CommandLine::ForCurrentProcess();
27   if (command_line->HasSwitch(switches::kDisableTestCompositor))
28     use_test_contexts = false;
29 
30 #if defined(OS_CHROMEOS)
31   // If the test is running on the chromeos envrionment (such as
32   // device or vm bots), always use real contexts.
33   if (base::SysInfo::IsRunningOnChromeOS())
34     use_test_contexts = false;
35 #endif
36 
37   if (!allow_test_contexts)
38     use_test_contexts = false;
39 
40   if (use_test_contexts) {
41     g_implicit_factory = new ui::TestContextFactory;
42   } else {
43     DVLOG(1) << "Using DefaultContextFactory";
44     scoped_ptr<ui::DefaultContextFactory> instance(
45         new ui::DefaultContextFactory());
46     if (instance->Initialize())
47       g_implicit_factory = instance.release();
48   }
49   ContextFactory::SetInstance(g_implicit_factory);
50 }
51 
TerminateContextFactoryForTests()52 void TerminateContextFactoryForTests() {
53   ContextFactory::SetInstance(NULL);
54   delete g_implicit_factory;
55   g_implicit_factory = NULL;
56 }
57 
58 }  // namespace ui
59