Remove the RenderProcessHost observer and attach the WebContentsObserver earlier...
[chromium-blink-merge.git] / sql / test / scoped_error_ignorer.h
blobe77717999d0790fa768211cf2e2af905e21ef3e6
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 #ifndef SQL_TEST_SCOPED_ERROR_IGNORER_H_
6 #define SQL_TEST_SCOPED_ERROR_IGNORER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "sql/connection.h"
13 namespace sql {
15 // sql::Connection and sql::Statement treat most SQLite errors as
16 // fatal in debug mode. The intention is to catch inappropriate uses
17 // of SQL before the code is shipped to production. This makes it
18 // challenging to write tests for things like recovery from
19 // corruption. This scoper can be used to ignore selected errors
20 // during a test. Errors are ignored globally (on all connections).
22 // Since errors can be very context-dependent, the class is pedantic -
23 // specific errors must be ignored, and every error ignored must be
24 // seen.
26 // NOTE(shess): There are still fatal error cases this does not
27 // address. If your test is handling database errors and you're
28 // hitting a case not handled, contact me.
29 class ScopedErrorIgnorer {
30 public:
31 ScopedErrorIgnorer();
32 ~ScopedErrorIgnorer();
34 // Add an error to ignore. Extended error codes can be ignored
35 // specifically, or the base code can ignore an entire group
36 // (SQLITE_IOERR_* versus SQLITE_IOERR).
37 void IgnoreError(int err);
39 // Allow containing test to check if the errors were encountered.
40 // Failure to call results in ADD_FAILURE() in destructor.
41 bool CheckIgnoredErrors();
43 // Record an error and check if it should be ignored.
44 bool ShouldIgnore(int err);
46 private:
47 // Storage for callback passed to Connection::SetErrorIgnorer().
48 Connection::ErrorIgnorerCallback callback_;
50 // Record whether CheckIgnoredErrors() has been called.
51 bool checked_;
53 // Errors to ignore.
54 std::set<int> ignore_errors_;
56 // Errors which have been ignored.
57 std::set<int> errors_ignored_;
59 DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer);
62 } // namespace sql
64 #endif // SQL_TEST_SCOPED_ERROR_IGNORER_H_