File: test_file_system.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (91 lines) | stat: -rw-r--r-- 3,260 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_file_system.h"

#include <stdint.h>
#include <string.h>

#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/file_io.h"
#include "ppapi/cpp/file_system.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(FileSystem);

bool TestFileSystem::Init() {
  return CheckTestingInterface() && EnsureRunningOverHTTP();
}

void TestFileSystem::RunTests(const std::string& filter) {
  RUN_CALLBACK_TEST(TestFileSystem, Open, filter);
  RUN_CALLBACK_TEST(TestFileSystem, MultipleOpens, filter);
  RUN_CALLBACK_TEST(TestFileSystem, ResourceConversion, filter);
}

std::string TestFileSystem::TestOpen() {
  TestCompletionCallback callback(instance_->pp_instance(), callback_type());

  // Open.
  pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
  callback.WaitForResult(file_system.Open(1024, callback.GetCallback()));
  CHECK_CALLBACK_BEHAVIOR(callback);
  ASSERT_EQ(PP_OK, callback.result());

  // Open aborted.
  int32_t rv = 0;
  {
    pp::FileSystem fs(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
    rv = fs.Open(1024, callback.GetCallback());
  }
  callback.WaitForAbortResult(rv);
  CHECK_CALLBACK_BEHAVIOR(callback);

  PASS();
}

std::string TestFileSystem::TestMultipleOpens() {
  // Should not allow multiple opens, regardless of whether or not the first
  // open has completed.
  TestCompletionCallback callback_1(instance_->pp_instance(), callback_type());
  pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
  int32_t rv_1 = file_system.Open(1024, callback_1.GetCallback());

  TestCompletionCallback callback_2(instance_->pp_instance(), callback_type());
  callback_2.WaitForResult(file_system.Open(1024, callback_2.GetCallback()));
  CHECK_CALLBACK_BEHAVIOR(callback_2);
  // FileSystem should not allow multiple opens.
  ASSERT_NE(PP_OK, callback_2.result());

  callback_1.WaitForResult(rv_1);
  CHECK_CALLBACK_BEHAVIOR(callback_1);
  ASSERT_EQ(PP_OK, callback_1.result());

  TestCompletionCallback callback_3(instance_->pp_instance(), callback_type());
  callback_3.WaitForResult(file_system.Open(1024, callback_3.GetCallback()));
  CHECK_CALLBACK_BEHAVIOR(callback_3);
  ASSERT_NE(PP_OK, callback_3.result());

  PASS();
}

std::string TestFileSystem::TestResourceConversion() {
  // Test conversion from file system Resource to FileSystem.
  pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
  pp::Resource file_system_resource(file_system);
  ASSERT_TRUE(pp::FileSystem::IsFileSystem(file_system_resource));
  pp::FileSystem file_system_resource_file_system(file_system_resource);
  ASSERT_FALSE(file_system_resource_file_system.is_null());

  // Test conversion that a non-file system Resource does not register as a
  // FileSystem. (We cannot test conversion, since this is an assertion on a
  // debug build.)
  pp::FileIO non_file_system(instance_);
  pp::Resource non_file_system_resource(non_file_system);
  ASSERT_FALSE(pp::FileSystem::IsFileSystem(non_file_system_resource));

  PASS();
}