Fix a couple bugs in the settings_page_header wrt breadcrumbs.
[chromium-blink-merge.git] / content / renderer / skia_benchmarking_extension_unittest.cc
blob0e97ae701dfc0cd8029290154977666aaac1bda5
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.
5 #include "content/renderer/skia_benchmarking_extension.h"
7 #include "base/values.h"
8 #include "skia/ext/benchmarking_canvas.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkGraphics.h"
13 namespace {
15 testing::AssertionResult HasArg(const base::ListValue* args,
16 const char name[]) {
17 const base::DictionaryValue* arg;
19 for (size_t i = 0; i < args->GetSize(); ++i) {
20 if (!args->GetDictionary(i, &arg) || arg->size() != 1)
21 return testing::AssertionFailure() << " malformed argument for index "
22 << i;
24 if (arg->HasKey(name))
25 return testing::AssertionSuccess() << " argument '" << name
26 << "' found at index " << i;
29 return testing::AssertionFailure() << "argument not found: '" << name << "'";
34 namespace content {
36 TEST(SkiaBenchmarkingExtensionTest, BenchmarkingCanvas) {
37 SkGraphics::Init();
39 // Prepare canvas and resources.
40 SkCanvas canvas(100, 100);
41 skia::BenchmarkingCanvas benchmarking_canvas(&canvas);
43 SkPaint red_paint;
44 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0));
45 SkRect fullRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
46 SkRect fillRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25),
47 SkIntToScalar(50), SkIntToScalar(50));
49 SkMatrix trans;
50 trans.setTranslate(SkIntToScalar(10), SkIntToScalar(10));
52 // Draw a trivial scene.
53 benchmarking_canvas.save();
54 benchmarking_canvas.clipRect(fullRect, SkRegion::kIntersect_Op, false);
55 benchmarking_canvas.setMatrix(trans);
56 benchmarking_canvas.drawRect(fillRect, red_paint);
57 benchmarking_canvas.restore();
59 // Verify the recorded commands.
60 const base::ListValue& ops = benchmarking_canvas.Commands();
61 ASSERT_EQ(ops.GetSize(), static_cast<size_t>(5));
63 size_t index = 0;
64 const base::DictionaryValue* op;
65 const base::ListValue* op_args;
66 std::string op_name;
68 ASSERT_TRUE(ops.GetDictionary(index++, &op));
69 EXPECT_TRUE(op->GetString("cmd_string", &op_name));
70 EXPECT_EQ(op_name, "Save");
71 ASSERT_TRUE(op->GetList("info", &op_args));
72 EXPECT_EQ(op_args->GetSize(), static_cast<size_t>(0));
74 ASSERT_TRUE(ops.GetDictionary(index++, &op));
75 EXPECT_TRUE(op->GetString("cmd_string", &op_name));
76 EXPECT_EQ(op_name, "ClipRect");
77 ASSERT_TRUE(op->GetList("info", &op_args));
78 EXPECT_EQ(op_args->GetSize(), static_cast<size_t>(3));
79 EXPECT_TRUE(HasArg(op_args, "rect"));
80 EXPECT_TRUE(HasArg(op_args, "op"));
81 EXPECT_TRUE(HasArg(op_args, "anti-alias"));
83 ASSERT_TRUE(ops.GetDictionary(index++, &op));
84 EXPECT_TRUE(op->GetString("cmd_string", &op_name));
85 EXPECT_EQ(op_name, "SetMatrix");
86 ASSERT_TRUE(op->GetList("info", &op_args));
87 EXPECT_EQ(op_args->GetSize(), static_cast<size_t>(1));
88 EXPECT_TRUE(HasArg(op_args, "matrix"));
90 ASSERT_TRUE(ops.GetDictionary(index++, &op));
91 EXPECT_TRUE(op->GetString("cmd_string", &op_name));
92 EXPECT_EQ(op_name, "DrawRect");
93 ASSERT_TRUE(op->GetList("info", &op_args));
94 EXPECT_EQ(op_args->GetSize(), static_cast<size_t>(2));
95 EXPECT_TRUE(HasArg(op_args, "rect"));
96 EXPECT_TRUE(HasArg(op_args, "paint"));
98 ASSERT_TRUE(ops.GetDictionary(index++, &op));
99 EXPECT_TRUE(op->GetString("cmd_string", &op_name));
100 EXPECT_EQ(op_name, "Restore");
101 ASSERT_TRUE(op->GetList("info", &op_args));
102 EXPECT_EQ(op_args->GetSize(), static_cast<size_t>(0));
105 } // namespace content