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

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: 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 // The factory may already have been initialized by the content layer, in
21 // which case, use that one.
22 //if (g_context_factory)
23 // return;
24 DCHECK(!g_implicit_factory) <<
25 "ContextFactory for tests already initialized.";
26
27 bool use_test_contexts = true;
28
29 // Always use test contexts unless the disable command line flag is used.
30 CommandLine* command_line = CommandLine::ForCurrentProcess();
31 if (command_line->HasSwitch(switches::kDisableTestCompositor))
32 use_test_contexts = false;
33
34 #if defined(OS_CHROMEOS)
35 // If the test is running on the chromeos envrionment (such as
36 // device or vm bots), always use real contexts.
37 if (base::SysInfo::IsRunningOnChromeOS())
38 use_test_contexts = false;
39 #endif
40
41 if (!allow_test_contexts)
42 use_test_contexts = false;
43
44 if (use_test_contexts) {
45 g_implicit_factory = new ui::TestContextFactory;
46 } else {
47 DVLOG(1) << "Using DefaultContextFactory";
48 scoped_ptr<ui::DefaultContextFactory> instance(
49 new ui::DefaultContextFactory());
50 if (instance->Initialize())
51 g_implicit_factory = instance.release();
52 }
53 ContextFactory::SetInstance(g_implicit_factory);
54 }
55
56 void TerminateContextFactoryForTests() {
57 ContextFactory::SetInstance(NULL);
58 delete g_implicit_factory;
59 g_implicit_factory = NULL;
60 }
61
62 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698