Disable some more flaky AppWindowInterceptAllKeysTest.* on Windows
[chromium-blink-merge.git] / sql / test / scoped_error_ignorer.cc
blobc5852295a190372bb29cab544516bbeb682ab9eb
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.
5 #include "sql/test/scoped_error_ignorer.h"
7 #include "base/bind.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace sql {
12 ScopedErrorIgnorer::ScopedErrorIgnorer()
13 : checked_(false) {
14 callback_ =
15 base::Bind(&ScopedErrorIgnorer::ShouldIgnore, base::Unretained(this));
16 Connection::SetErrorIgnorer(&callback_);
19 ScopedErrorIgnorer::~ScopedErrorIgnorer() {
20 EXPECT_TRUE(checked_) << " Test must call CheckIgnoredErrors()";
21 Connection::ResetErrorIgnorer();
24 void ScopedErrorIgnorer::IgnoreError(int err) {
25 EXPECT_EQ(0u, ignore_errors_.count(err))
26 << " Error " << err << " is already ignored";
27 ignore_errors_.insert(err);
30 bool ScopedErrorIgnorer::CheckIgnoredErrors() {
31 checked_ = true;
32 return errors_ignored_ == ignore_errors_;
35 bool ScopedErrorIgnorer::ShouldIgnore(int err) {
36 // Look for extended code.
37 if (ignore_errors_.count(err) > 0) {
38 // Record that the error was seen and ignore it.
39 errors_ignored_.insert(err);
40 return true;
43 // Trim extended codes and check again.
44 int base_err = err & 0xff;
45 if (ignore_errors_.count(base_err) > 0) {
46 // Record that the error was seen and ignore it.
47 errors_ignored_.insert(base_err);
48 return true;
51 // Unexpected error.
52 ADD_FAILURE() << " Unexpected SQLite error " << err;
54 // TODO(shess): If it never makes sense to pass through an error
55 // under the test harness, then perhaps the ignore callback
56 // signature should be changed.
57 return true;
60 } // namespace sql