Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / test / ispy / common / mock_cloud_bucket.py
blob803fd571196151901e9dbab9cf0d5642557fbf49
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 """Subclass of CloudBucket used for testing."""
7 import os
8 import sys
10 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
11 import cloud_bucket
14 class MockCloudBucket(cloud_bucket.BaseCloudBucket):
15 """Subclass of CloudBucket used for testing."""
17 def __init__(self):
18 """Initializes the MockCloudBucket with its datastore.
20 Returns:
21 An instance of MockCloudBucket.
22 """
23 self.datastore = {}
25 def Reset(self):
26 """Clears the MockCloudBucket's datastore."""
27 self.datastore = {}
29 # override
30 def UploadFile(self, path, contents, content_type):
31 self.datastore[path] = contents
33 # override
34 def DownloadFile(self, path):
35 if self.datastore.has_key(path):
36 return self.datastore[path]
37 else:
38 raise cloud_bucket.FileNotFoundError
40 # override
41 def UpdateFile(self, path, contents):
42 if not self.FileExists(path):
43 raise cloud_bucket.FileNotFoundError
44 self.UploadFile(path, contents, '')
46 # override
47 def RemoveFile(self, path):
48 if self.datastore.has_key(path):
49 self.datastore.pop(path)
51 # override
52 def FileExists(self, path):
53 return self.datastore.has_key(path)
55 # override
56 def GetImageURL(self, path):
57 if self.datastore.has_key(path):
58 return path
59 else:
60 raise cloud_bucket.FileNotFoundError
62 # override
63 def GetAllPaths(self, prefix):
64 return (item[0] for item in self.datastore.items()
65 if item[0].startswith(prefix))