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

Side by Side Diff: ui/compositor/test/context_factories_for_test.cc

Issue 45963003: Move test-only ContextFactory implementations out of production targets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert bad ui/base changes Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 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
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
52 void TerminateContextFactoryForTests() {
53 ContextFactory::SetInstance(NULL);
54 delete g_implicit_factory;
55 g_implicit_factory = NULL;
56 }
57
58 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698