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 // These tests are run twice:
6 // Once in a gpu test with an in-process WebGraphicsContext3D.
7 // Once in a browsertest with a gpu-process WebGraphicsContext3D.
8
9 #include "base/bind.h"
10 #include "base/run_loop.h"
11 #include "gpu/GLES2/gl2extchromium.h"
12 #include "gpu/command_buffer/client/context_support.h"
13
14 namespace {
15
16 class SignalTest : public ContextTestBase {
17 public:
RunOnlyOnce(base::Closure cb,int * tmp)18 static void RunOnlyOnce(base::Closure cb, int* tmp) {
19 CHECK_EQ(*tmp, 0);
20 ++*tmp;
21 cb.Run();
22 }
23
24 // These tests should time out if the callback doesn't get called.
TestSignalSyncPoint(unsigned sync_point)25 void TestSignalSyncPoint(unsigned sync_point) {
26 base::RunLoop run_loop;
27 context_support_->SignalSyncPoint(sync_point, run_loop.QuitClosure());
28 run_loop.Run();
29 }
30
31 // These tests should time out if the callback doesn't get called.
TestSignalQuery(blink::WebGLId query)32 void TestSignalQuery(blink::WebGLId query) {
33 base::RunLoop run_loop;
34 context_support_->SignalQuery(
35 query,
36 base::Bind(
37 &RunOnlyOnce, run_loop.QuitClosure(), base::Owned(new int(0))));
38 run_loop.Run();
39 }
40 };
41
CONTEXT_TEST_F(SignalTest,BasicSignalSyncPointTest)42 CONTEXT_TEST_F(SignalTest, BasicSignalSyncPointTest) {
43 if (!context_)
44 return;
45
46 TestSignalSyncPoint(context_->insertSyncPoint());
47 };
48
CONTEXT_TEST_F(SignalTest,InvalidSignalSyncPointTest)49 CONTEXT_TEST_F(SignalTest, InvalidSignalSyncPointTest) {
50 if (!context_)
51 return;
52
53 // Signalling something that doesn't exist should run the callback
54 // immediately.
55 TestSignalSyncPoint(1297824234);
56 };
57
CONTEXT_TEST_F(SignalTest,BasicSignalQueryTest)58 CONTEXT_TEST_F(SignalTest, BasicSignalQueryTest) {
59 if (!context_)
60 return;
61
62 unsigned query = context_->createQueryEXT();
63 context_->beginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, query);
64 context_->finish();
65 context_->endQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
66 TestSignalQuery(query);
67 context_->deleteQueryEXT(query);
68 };
69
CONTEXT_TEST_F(SignalTest,SignalQueryUnboundTest)70 CONTEXT_TEST_F(SignalTest, SignalQueryUnboundTest) {
71 if (!context_)
72 return;
73
74 blink::WebGLId query = context_->createQueryEXT();
75 TestSignalQuery(query);
76 context_->deleteQueryEXT(query);
77 };
78
CONTEXT_TEST_F(SignalTest,InvalidSignalQueryUnboundTest)79 CONTEXT_TEST_F(SignalTest, InvalidSignalQueryUnboundTest) {
80 if (!context_)
81 return;
82
83 // Signalling something that doesn't exist should run the callback
84 // immediately.
85 TestSignalQuery(928729087);
86 TestSignalQuery(928729086);
87 TestSignalQuery(928729085);
88 TestSignalQuery(928729083);
89 TestSignalQuery(928729082);
90 TestSignalQuery(928729081);
91 };
92
93 };
94